Detecting database column data type of smalldatetime vs. datetime?

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

Miha Markic

You should use SqlConnection.GetSchema method to retrieve these kind of
information.
 
J

Jen

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

Miha Markic

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top