Get SQL data Type

G

Guest

How can you get the SQL DATA TYPE of a column in a DataSet. Now I am not talking about the System.Datatype but the SQL one. I am connecting Via SQL Server 2000

Under the Column dataType property (myDataSet.Tables("TEST").Columns(i).DataType.ToString) I get the System Type's such as System.Int64, System.Int32, etc... What I want is the SQL Data Type equivalent, such as SQLDBType.varChar, SQLDBType.nvarChar, etc..

Thanks
 
W

William Ryan eMVP

Angel:

If you have the System.Type, can't you just convert it with the list of
conversion values?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemdatasqldbtypeclasstopic.asp I don't know of any inherent method
(although there may be one) but since DataSets are members of System.Data,
I'd be surprised if there was a built in method to get it's SqlDbType (also
b/c some of the types could map to different types of Sql Server values)

At worst though you could look at what maps to each type and write it
yourself.

HTH,

Bill
Angel said:
How can you get the SQL DATA TYPE of a column in a DataSet. Now I am not
talking about the System.Datatype but the SQL one. I am connecting Via SQL
Server 2000.
Under the Column dataType property
(myDataSet.Tables("TEST").Columns(i).DataType.ToString) I get the System
Type's such as System.Int64, System.Int32, etc... What I want is the SQL
Data Type equivalent, such as SQLDBType.varChar, SQLDBType.nvarChar, etc...
 
G

Guest

I agree with William. There's no inherent way to find out the exact SQL db type of a column from a dataset.
You can try writing the Xml schema(DataSet.WriteXmlSchema("filename")) of the datatable in the dataset and you'll see it'll only have .NET types

Here's a good resource on sql data type mapping to the various data providers in .NET
http://msdn.microsoft.com/library/d...taproviderdatatypestonetframeworkdatatypes.as

Why do you want to do this? If it's for administrative work you can always query the system tables in SQL for the information you are looking for

Suresh

----- Angel wrote: ----

How can you get the SQL DATA TYPE of a column in a DataSet. Now I am not talking about the System.Datatype but the SQL one. I am connecting Via SQL Server 2000

Under the Column dataType property (myDataSet.Tables("TEST").Columns(i).DataType.ToString) I get the System Type's such as System.Int64, System.Int32, etc... What I want is the SQL Data Type equivalent, such as SQLDBType.varChar, SQLDBType.nvarChar, etc..

Thanks
 

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