0

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?

Drammy
  • 940
  • 12
  • 30
  • you might be able to do something to check when reading whether the type is `SqlDbType.DateTime2`. Is changing the database type to be datetime2 out of the question? – IndigoDelta May 26 '11 at 16:11
  • Yes, my solution has to assume the Sql table could have any columns and datatypes in it. It could also be a SQL 2005 db - datetime only... – Drammy May 26 '11 at 23:42

2 Answers2

1

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

Ed Charbeneau
  • 4,501
  • 23
  • 23
  • 1
    Sure, I understand the differences of the SQL datatypes. My problem is that the C# properties of a DataColumn born from a datetime Sql column has exactly the same properties to a DataColumn born from a datetime2 Sql columm. I need to find a way to ensure a date is valid for what could potentially be a datetime Sql columm. – Drammy May 26 '11 at 23:40
1

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

Drammy
  • 940
  • 12
  • 30