Drammy
Drammy

Reputation: 988

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?

Upvotes: 0

Views: 925

Answers (2)

Drammy
Drammy

Reputation: 988

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...

Upvotes: 1

Ed Charbeneau
Ed Charbeneau

Reputation: 4634

The precision and range is different from DateTime to DateTime2, you can probably derive a validation from this blog post.

Upvotes: 1

Related Questions