get the correct datatype

  • Thread starter Thread starter Trainee
  • Start date Start date
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..
 
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
 
Hi kalpesh
i don't get what u r saying?????could u explain this in more
detailed way????
 
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
 
Back
Top