get the correct datatype

T

Trainee

hi

i am using OleDbSchemaGuid.Columns method to return the column
names,datatype and other details of a table...but this method returns
datatype as a number and that number corresponds to a data type but the
problem is lots of data types have same number

for eg. text,char,varchar have same number 129
nchar,ntext,nvarchar have number 130
so am not able to differentiate between the data types based on these
numbers...my code snippet is as follows

OleDbConnection connection = new OleDbConnection(connectionstring);
connection.open;
DataTable schemaTable =
connection.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new
object[]{null,null,table_name,null});
foreach(DataRow schemaRow in schemaTable.Rows)
{
schemaRow["column_name"].ToString(); // returns the column name
schemaRow["data_type"].ToString(); // returns the data type as a number....
}
connection.close;

plz help me out to differentiate between the data types..
 
K

Kalpesh

Hi,

I guess it wil be better to run a sql statement (which doesnt return
any rows) to get the schema of the table name.

Use a dataset with query "select * from table_name where 1 = 0"
This will fetch the field names & their types etc

HTH
Kalpesh
 
T

Trainee

Hi kalpesh
i don't get what u r saying?????could u explain this in more
detailed way????
 
K

Kalpesh

Hi,

Just like you said

<snip>
for eg. text,char,varchar have same number 129
nchar,ntext,nvarchar have number 130
</snip>

If you wish to get the exact datatype, you can query a table by opening
a dataset
with query (select * from table_name where 1 = 2)

The above statement will return a blank datatable with fields in it.
This will also return the fields according to the DB that you are
querying

Does this help ?

Kalpesh
 

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