steve
Tue Oct 19 12:30:08 CDT 2004
This is a multi-part message in MIME format.
------=_NextPart_000_0075_01C4B5DF.C07C90E0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
what do you mean ???
I am using a datareader and a listview control
I dont think either have this method.
"William (Bill) Vaughn" <billvaRemoveThis@nwlink.com> a =E9crit dans le =
message de news:OQWr5wftEHA.2800@tk2msftngp13.phx.gbl...
Or, you could let ADO.NET do it--use Fill.
--=20
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.=20
This posting is provided "AS IS" with no warranties, and confers no =
rights.
__________________________________
"Imran Koradia" <nospam@microsoft.com> wrote in message =
news:uvlkJDftEHA.2300@TK2MSFTNGP09.phx.gbl...
You can use the GetFieldType method to retrieve the type of the =
field. Something like this:
If reader.GetFieldType(col) Is GetType(String) Then
' its a string type
Return reader.GetString(col) =20
ElseIf reader.GetFieldType(col) Is GetType(Integer) Then
' its an integer type
Return reader.GetInt32(col)
' add other types..
...
...
End If
It seems a bit verbose but it'll work.
hope that helps..
Imran.
"steve" <noemail.@try.com> wrote in message =
news:7eadd.80626$ct3.1633387@wagner.videotron.net...
Hi,
I have a few examples and things are quite clear with using a =
datareader (reading data, naming column headers etc.), and populating a =
listview.
However: (!!!) In all of the examples we know beforehand the =
number of fields and therefore the data type (Int, Date, String etc) =
since the SELECT string is constant.
My problem is with variable strings that get constructed at =
runtime. Then, since i do not know beforehand what exactly is my =
first,second, etc. field, I CANNOT use :
myDataReader.GetString(0) or myData.GetInt32(0),etc. since io do =
not know the type beforehand.
Is there a way around this? I really dont mind getting them all as =
text so is the an CType analogous method I could use . Something like =
casting BEFORE reading ??
ANY help would be appreciated,
Thanx
-steve
------=_NextPart_000_0075_01C4B5DF.C07C90E0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1476" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>what do you mean ???</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I am using a datareader and a listview=20
control</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I dont think either have this =
method.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>"William (Bill) Vaughn" <<A=20
href=3D"mailto:billvaRemoveThis@nwlink.com">billvaRemoveThis@nwlink.com</=
A>> a=20
=E9crit dans le message de <A=20
href=3D"news:OQWr5wftEHA.2800@tk2msftngp13.phx.gbl">news:OQWr5wftEHA.2800=
@tk2msftngp13.phx.gbl</A>...</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV><FONT size=3D2>Or, you could let ADO.NET do it--use =
Fill.</FONT></DIV>
<DIV><BR>-- <BR>____________________________________<BR>William (Bill) =
Vaughn<BR>Author, Mentor, Consultant<BR>Microsoft MVP<BR><A=20
href=3D"
http://www.betav.com">www.betav.com</A><BR>Please reply only =
to the=20
newsgroup so that others can benefit. <BR>This posting is provided "AS =
IS"=20
with no warranties, and confers no=20
rights.<BR>__________________________________<BR></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Imran Koradia" <<A=20
href=3D"mailto:nospam@microsoft.com">nospam@microsoft.com</A>> =
wrote in=20
message <A=20
=
href=3D"news:uvlkJDftEHA.2300@TK2MSFTNGP09.phx.gbl">news:uvlkJDftEHA.2300=
@TK2MSFTNGP09.phx.gbl</A>...</DIV>
<DIV><FONT face=3DArial size=3D2>You can use the GetFieldType method =
to retrieve=20
the type of the field. Something like this:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>If reader.GetFieldType(col) Is =
GetType(String)=20
Then</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> ' its a string=20
type</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =20
=
Return reader.GetString(col) &nbs=
p;=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>ElseIf reader.GetFieldType(col) Is=20
GetType(Integer) Then</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> ' its an integer =
type</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> Return=20
reader.GetInt32(col)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>' add other types..</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>End If</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>It seems a bit verbose but it'll=20
work.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>hope that helps..</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Imran.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"steve" <<A=20
href=3D"mailto:noemail.@try.com">noemail.@try.com</A>> wrote in =
message=20
<A=20
=
href=3D"news:7eadd.80626$ct3.1633387@wagner.videotron.net">news:7eadd.806=
26$ct3.1633387@wagner.videotron.net</A>...</DIV>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I have a few examples and things =
are quite=20
clear with using a datareader (reading data, naming column headers =
etc.), and populating a listview.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>However: (!!!) In all of the =
examples we know=20
beforehand the number of fields and therefore the data type (Int, =
Date,=20
String etc) since the SELECT string is constant.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>My problem is with variable =
strings that get=20
constructed at runtime. Then, since i do not know beforehand what =
exactly=20
is my first,second, etc. field, I CANNOT use :</FONT></DIV>
<DIV>
<P><FONT face=3DArial size=3D2>myDataReader.GetString(0) or=20
myData.GetInt32(0),etc. since io do not know the type=20
beforehand.</FONT></P>
<P><FONT face=3DArial size=3D2>Is there a way around this? I =
really dont mind=20
getting them all as text so is the an CType analogous method I =
could use .=20
Something like casting BEFORE reading ??</FONT></P>
<P><FONT face=3DArial size=3D2>ANY help would be =
appreciated,</FONT></P>
<P><FONT face=3DArial size=3D2>Thanx</FONT></P>
<P><FONT face=3DArial size=3D2>-steve</FONT></P>
<P><FONT face=3DArial=20
size=3D2></FONT> </P></DIV></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></=
BODY></HTML>
------=_NextPart_000_0075_01C4B5DF.C07C90E0--