Getting a DataColumn's Type

  • Thread starter Thread starter David P. Donahue
  • Start date Start date
D

David P. Donahue

Probably a simple question...

I have a DataSet which gets its schema from an external xsd file. At
one point in the code, I am iterating through all the records in one of
the DataSet's DataTables, by means of a DataView of that DataTable. I
need to perform some logic on each field in each column, conditionally
based on that field's data type.

So, my question is, how should my conditional look for determining the
column type? Pseudo-code would be as follows:

if (column.type == string)
do something;
else if (column.type == datetime)
do something else;
else
do nothing;


Regards,
David P. Donahue
(e-mail address removed)
http://www.cyber0ne.com
 
David,

Check the DataType property on the DataColumn as you iterate through the
columns on the data source (you can get the Colums property from the
DataTable itself, which would be exposed from the view through the Table
property on the DataView instance).

This will return the Type in .NET for the column.

Hope this helps.
 
Back
Top