PC Review


Reply
Thread Tools Rate Thread

Detect each column's data type of SalDataReader, DataSet, DataTable

 
 
Hardy Wang
Guest
Posts: n/a
 
      27th Feb 2004
Hi all,
I am just wandering, is it possible to programmatically detect each
column's data type of SalDataReader, DataSet.Tables[i], DataTable?
Thanks for any suggestion!

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy


 
Reply With Quote
 
 
 
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      27th Feb 2004
Hi,

There is SqlDataReader.GetFieldType method and DataColumn.DataType property.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"Hardy Wang" <(E-Mail Removed)> wrote in message
news:ehoJQ%23T$(E-Mail Removed)...
> Hi all,
> I am just wandering, is it possible to programmatically detect each
> column's data type of SalDataReader, DataSet.Tables[i], DataTable?
> Thanks for any suggestion!
>
> --
> WWW: http://hardywang.1accesshost.com
> ICQ: 3359839
> yours Hardy
>
>



 
Reply With Quote
 
Hardy Wang
Guest
Posts: n/a
 
      27th Feb 2004
Thanks, I found another wway like:
object o = dataReader.GetValue(i);
Type t = o.GetType();
t.FullName;

I think they work pretty the same way.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:uNW1lDU$(E-Mail Removed)...
> Hi,
>
> There is SqlDataReader.GetFieldType method and DataColumn.DataType

property.
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & software development
> miha at rthand com
> www.rthand.com
>
> "Hardy Wang" <(E-Mail Removed)> wrote in message
> news:ehoJQ%23T$(E-Mail Removed)...
> > Hi all,
> > I am just wandering, is it possible to programmatically detect each
> > column's data type of SalDataReader, DataSet.Tables[i], DataTable?
> > Thanks for any suggestion!
> >
> > --
> > WWW: http://hardywang.1accesshost.com
> > ICQ: 3359839
> > yours Hardy
> >
> >

>
>



 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      27th Feb 2004
Hardy Wang <(E-Mail Removed)> wrote:
> Thanks, I found another wway like:
> object o = dataReader.GetValue(i);
> Type t = o.GetType();
> t.FullName;
>
> I think they work pretty the same way.


Not necessarily - if the value is DbNull, for instance, that will give
a very different result.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Hardy Wang
Guest
Posts: n/a
 
      27th Feb 2004
I ran some test. If the result is null, it will return DBNull, this is also
what I need.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"Jon Skeet [C# MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hardy Wang <(E-Mail Removed)> wrote:
> > Thanks, I found another wway like:
> > object o = dataReader.GetValue(i);
> > Type t = o.GetType();
> > t.FullName;
> >
> > I think they work pretty the same way.

>
> Not necessarily - if the value is DbNull, for instance, that will give
> a very different result.
>
> --
> Jon Skeet - <(E-Mail Removed)>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too



 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      27th Feb 2004
Hardy Wang <(E-Mail Removed)> wrote:
> I ran some test. If the result is null, it will return DBNull, this is also
> what I need.


If that's what you need, that's fine - but it's certainly not what you
originally asked for (the column type) nor is it what Miha's code would
have given you.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
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
Re: What type should I set the dataTable column to for byte[] type of Morten Wennevik [C# MVP] Microsoft C# .NET 2 18th Jan 2007 03:07 PM
define dataset column for timestamp data type in MS SQL server John Yung Microsoft ADO .NET 2 30th Nov 2005 04:48 PM
New Column to DataSet.DataTable Xarky Microsoft C# .NET 4 26th Apr 2005 01:06 PM
Edit data in a dataset datatable column automatically =?Utf-8?B?SG9tZXI=?= Microsoft ADO .NET 1 17th Mar 2004 11:24 AM
Detect each column's data type of SalDataReader, DataSet, DataTable Hardy Wang Microsoft ADO .NET 5 27th Feb 2004 03:48 PM


Features
 

Advertising
 

Newsgroups
 


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