Detecting database column data type of smalldatetime vs. datetime?

  • Thread starter Thread starter Jen
  • Start date Start date
J

Jen

Is there a way for C# ADO.NET code to determine whether a SQL Server column
data type is smalldatetime vs. datetime? It looks like DataColumn.DataType
makes no distinction, both return DateTime.
 
You should use SqlConnection.GetSchema method to retrieve these kind of
information.
 
I'm using OleDb. Would I use OleDbConnection.GetOldDbSchemaTable? I'm
trying that but both smalldatetime and datetime data types seem to return
135.

Can I not distinguish between the two data types when using OleDb?


Miha Markic said:
You should use SqlConnection.GetSchema method to retrieve these kind of
information.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Jen said:
Is there a way for C# ADO.NET code to determine whether a SQL Server
column data type is smalldatetime vs. datetime? It looks like
DataColumn.DataType makes no distinction, both return DateTime.
 
If GetOldDbSchemaTable doesn't suite you then you should use DDL statements
(i.e. sp_columns stored procedure should do)

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Jen said:
I'm using OleDb. Would I use OleDbConnection.GetOldDbSchemaTable? I'm
trying that but both smalldatetime and datetime data types seem to return
135.

Can I not distinguish between the two data types when using OleDb?


Miha Markic said:
You should use SqlConnection.GetSchema method to retrieve these kind of
information.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Jen said:
Is there a way for C# ADO.NET code to determine whether a SQL Server
column data type is smalldatetime vs. datetime? It looks like
DataColumn.DataType makes no distinction, both return DateTime.
 
Back
Top