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

  • Thread starter Thread starter Hardy Wang
  • Start date Start date
H

Hardy Wang

Hi all,
I am just wandering, is it possible to programmatically detect each
column's data type of SalDataReader, DataSet.Tables, DataTable?
Thanks for any suggestion!
 
Hi,

There is SqlDataReader.GetFieldType method and DataColumn.DataType property.
 
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 said:
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 said:
Hi all,
I am just wandering, is it possible to programmatically detect each
column's data type of SalDataReader, DataSet.Tables, DataTable?
Thanks for any suggestion!

 
Hardy Wang said:
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.
 
I ran some test. If the result is null, it will return DBNull, this is also
what I need.
 
Hardy Wang said:
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.
 
Back
Top