This is a multi-part message in MIME format.

------=_NextPart_000_0059_01C4B5CD.2DB31250
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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_0059_01C4B5CD.2DB31250
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>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have a few examples and things are =
quite clear=20
with using a datareader (reading data, naming column headers =
etc.),&nbsp;and=20
populating a listview.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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, =
String=20
etc) since the SELECT string is constant.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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 is my=20
first,second, etc. field, I CANNOT use :</FONT></DIV>
<DIV>
<P><FONT face=3DArial size=3D2>myDataReader.GetString(0) or =
myData.GetInt32(0),etc.=20
&nbsp; since io do not know the type 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 size=3D2></FONT>&nbsp;</P></DIV></BODY></HTML>

------=_NextPart_000_0059_01C4B5CD.2DB31250--

Re: Newbie: Detecting type of field contents in datareader by W

W
Tue Oct 19 10:30:01 CDT 2004

This is a multi-part message in MIME format.

------=_NextPart_000_0026_01C4B5CE.F8971D80
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

.GetValue may be an option - but if you need the schema information you =
can use the GetSchemaTable method (if you're using SqlConnection) =
http://www.knowdotnet.com/articles/schemas2.html or GetOleDbSchemaTable =
otherwise.

HTH,

Bill

--=20
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"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_0026_01C4B5CE.F8971D80
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>.GetValue may be an option - but if you =
need the=20
schema information you can use the GetSchemaTable method (if you're =
using=20
SqlConnection) <A=20
href=3D"http://www.knowdotnet.com/articles/schemas2.html">http://www.know=
dotnet.com/articles/schemas2.html</A>&nbsp;=20
or GetOleDbSchemaTable otherwise.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>HTH,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Bill</FONT></DIV>
<DIV><BR>-- <BR>W.G. Ryan, MVP</DIV>
<DIV>&nbsp;</DIV>
<DIV><A href=3D"http://www.tibasolutions.com">www.tibasolutions.com</A> =
| <A=20
href=3D"http://www.devbuzz.com">www.devbuzz.com</A> | <A=20
href=3D"http://www.knowdotnet.com">www.knowdotnet.com</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>"steve" &lt;<A =
href=3D"mailto:noemail.@try.com">noemail.@try.com</A>&gt;=20
wrote in message <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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have a few examples and things are =
quite clear=20
with using a datareader (reading data, naming column headers =
etc.),&nbsp;and=20
populating a listview.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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, String=20
etc) since the SELECT string is constant.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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 is=20
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. &nbsp; 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 =
size=3D2></FONT>&nbsp;</P></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0026_01C4B5CE.F8971D80--


Re: Newbie: Detecting type of field contents in datareader by Imran

Imran
Tue Oct 19 10:32:40 CDT 2004

This is a multi-part message in MIME format.

------=_NextPart_000_0234_01C4B5CF.583A25C0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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_0234_01C4B5CF.583A25C0
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>You can use the GetFieldType method to =
retrieve the=20
type of the field. Something like this:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>If reader.GetFieldType(col) Is =
GetType(String)=20
Then</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; ' its a string =
type</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;=20
Return&nbsp;reader.GetString(col)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>ElseIf reader.GetFieldType(col) Is =
GetType(Integer)=20
Then</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; ' its an integer=20
type</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Return=20
reader.GetInt32(col)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>It seems a bit verbose but it'll =
work.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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>&nbsp;</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" &lt;<A =
href=3D"mailto:noemail.@try.com">noemail.@try.com</A>&gt;=20
wrote in message <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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have a few examples and things are =
quite clear=20
with using a datareader (reading data, naming column headers =
etc.),&nbsp;and=20
populating a listview.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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, String=20
etc) since the SELECT string is constant.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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 is=20
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. &nbsp; 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 =
size=3D2></FONT>&nbsp;</P></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0234_01C4B5CF.583A25C0--


Re: Newbie: Detecting type of field contents in datareader by William

William
Tue Oct 19 11:54:04 CDT 2004

This is a multi-part message in MIME format.

------=_NextPart_000_0025_01C4B5C1.916334D0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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_0025_01C4B5C1.916334D0
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.2900.2523" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Or, you could let ADO.NET do it--use =
Fill.</FONT></DIV>
<DIV><BR>-- <BR>____________________________________<BR>William (Bill)=20
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" with=20
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" &lt;<A=20
href=3D"mailto:nospam@microsoft.com">nospam@microsoft.com</A>&gt; =
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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>If reader.GetFieldType(col) Is =
GetType(String)=20
Then</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; ' its a string=20
type</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;=20
=
Return&nbsp;reader.GetString(col)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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>&nbsp;&nbsp;&nbsp; ' its an integer=20
type</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Return=20
reader.GetInt32(col)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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>&nbsp;</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" &lt;<A =
href=3D"mailto:noemail.@try.com">noemail.@try.com</A>&gt;=20
wrote in message <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>&nbsp;</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=20
etc.),&nbsp;and populating a listview.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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>&nbsp;</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 is=20
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. &nbsp; 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>&nbsp;</P></DIV></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0025_01C4B5C1.916334D0--


Re: Newbie: Detecting type of field contents in datareader by steve

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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I dont think either have this =
method.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>"William (Bill) Vaughn" &lt;<A=20
href=3D"mailto:billvaRemoveThis@nwlink.com">billvaRemoveThis@nwlink.com</=
A>&gt; 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" &lt;<A=20
href=3D"mailto:nospam@microsoft.com">nospam@microsoft.com</A>&gt; =
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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>If reader.GetFieldType(col) Is =
GetType(String)=20
Then</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; ' its a string=20
type</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;=20
=
Return&nbsp;reader.GetString(col)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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>&nbsp;&nbsp;&nbsp; ' its an integer =

type</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Return=20
reader.GetInt32(col)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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>&nbsp;</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" &lt;<A=20
href=3D"mailto:noemail.@try.com">noemail.@try.com</A>&gt; 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>&nbsp;</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.),&nbsp;and populating a listview.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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>&nbsp;</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. &nbsp; 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>&nbsp;</P></DIV></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></=
BODY></HTML>

------=_NextPart_000_0075_01C4B5DF.C07C90E0--


Re: Newbie: Detecting type of field contents in datareader by Imran

Imran
Tue Oct 19 12:34:56 CDT 2004

This is a multi-part message in MIME format.

------=_NextPart_000_02D4_01C4B5E0.6C6ED0C0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Bill,

Do you mean the dataadapter fill method? The OP mentioned using the =
datareader..Or is it something I'm missing?

Imran.
"William (Bill) Vaughn" <billvaRemoveThis@nwlink.com> wrote in message =
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_02D4_01C4B5E0.6C6ED0C0
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>Bill,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Do you mean the dataadapter fill =
method? The OP=20
mentioned using the datareader..Or is it something I'm =
missing?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Imran.</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>"William (Bill) Vaughn" &lt;<A=20
=
href=3D"mailto:billvaRemoveThis@nwlink.com">billvaRemoveThis@nwlink.com</=
A>&gt;=20
wrote in message <A=20
=
href=3D"news:OQWr5wftEHA.2800@tk2msftngp13.phx.gbl">news:OQWr5wftEHA.2800=
@tk2msftngp13.phx.gbl</A>...</DIV>
<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" &lt;<A=20
href=3D"mailto:nospam@microsoft.com">nospam@microsoft.com</A>&gt; =
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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>If reader.GetFieldType(col) Is =
GetType(String)=20
Then</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; ' its a string=20
type</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;=20
=
Return&nbsp;reader.GetString(col)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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>&nbsp;&nbsp;&nbsp; ' its an integer =

type</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Return=20
reader.GetInt32(col)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>' add other types..</FONT></DIV>
<DIV><FONT fa