PC Review


Reply
Thread Tools Rate Thread

Checking for datareader returned types at runtime

 
 
=?Utf-8?B?Sm/Do28gQ29zdGE=?=
Guest
Posts: n/a
 
      24th Mar 2006
dr is a dataset, str1 is a string. How can I know the type inside the
datareader field?
I tried:

if(dr.GetValue(n) is System.Int32)
str1=Convert.ToString(dr.GetSqlInt32(n))
else
str1=dr.GetString(n)

But the compiler warns the if is always false.
Thanks in advance
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm/Do28gQ29zdGE=?=
Guest
Posts: n/a
 
      24th Mar 2006
Sorry, dr is a SqlDatareader

"João Costa" wrote:

> dr is a dataset, str1 is a string. How can I know the type inside the
> datareader field?
> I tried:
>
> if(dr.GetValue(n) is System.Int32)
> str1=Convert.ToString(dr.GetSqlInt32(n))
> else
> str1=dr.GetString(n)
>
> But the compiler warns the if is always false.
> Thanks in advance

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm/Do28gQ29zdGE=?=
Guest
Posts: n/a
 
      24th Mar 2006
I solved the problem with:
if(rsAux.GetFieldType(n).FullName == "System.Int32" )


"João Costa" wrote:

> Sorry, dr is a SqlDatareader
>
> "João Costa" wrote:
>
> > dr is a dataset, str1 is a string. How can I know the type inside the
> > datareader field?
> > I tried:
> >
> > if(dr.GetValue(n) is System.Int32)
> > str1=Convert.ToString(dr.GetSqlInt32(n))
> > else
> > str1=dr.GetString(n)
> >
> > But the compiler warns the if is always false.
> > Thanks in advance

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 error "some chart types cannot be combined with other chart types. Select a different chart types" roadsidetree Microsoft Excel Charting 17 12th May 2010 06:51 PM
How to process datareader nulls coming from datareader? JB Microsoft C# .NET 4 3rd Nov 2008 01:56 AM
Should I close a datareader returned using daab? hansiman Microsoft ASP .NET 7 11th May 2005 01:02 PM
DataReader and Returned Parms Jim Heavey Microsoft ADO .NET 3 19th Dec 2003 09:39 PM
records returned from datareader error Davef Microsoft ASP .NET 1 28th Aug 2003 04:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:57 AM.