Search code examples
c#datetimetypesdatacolumndatetime2

DataColumn - how to distinguish datetime or datetime2


I am having trouble identifying the type of a datetime DataColumn.

If I grab a DataTable from SQL 2008 a datetime DataColumn could be a datetime or datetime2 but there appears to be no difference when in C#.

I need to validate data prior to loading into SQL...

Any ideas?


Solution

  • I have decided to scrap using the DataColumn properties for reading a table's schema as it is inaccurate in a few places (Unique always = false, Length always = -1).

    I ended up retrieving the schema definition from the Sql INFORMATION_SCHEMA views instead.

    Anyone know why these properties are useless in reading a DataTable's schema? They simply don't depict the true structure of the database table...