Getting the column datatype and size?

  • Thread starter Thread starter RA
  • Start date Start date
R

RA

Hi

Is it possible to dynamicaly get the table columns and their data type and
size from sql server database? If not then how does the designed in vs does
this when you drug and drop a data adapter?

Thanks,
Ronen
 
Hi RA;

Try this:
oleDbConnection1.Open();

DataTable schemaTable =
oleDbConnection1.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,

new object[] {null, null, "YourTableName"});

oleDbConnection1.Close();

It stores all information you need for all columns into schemaTable
DataTable.
 
How do you do it with sql server(SqlConnection)?

Ronen

Miha Markic said:
Hi RA;

Try this:
oleDbConnection1.Open();

DataTable schemaTable =
oleDbConnection1.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,

new object[] {null, null, "YourTableName"});

oleDbConnection1.Close();

It stores all information you need for all columns into schemaTable
DataTable.

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com

RA said:
Hi

Is it possible to dynamicaly get the table columns and their data type and
size from sql server database? If not then how does the designed in vs does
this when you drug and drop a data adapter?

Thanks,
Ronen
 
It works essentially the same way. Miha's example is a great method and all
you need to do is change it so SQLClient.

I prefer his method, but you can also use DataReader.GetSchemaTable method
if you want to use a 'connected' method.

HTH,
Bill
RA said:
How do you do it with sql server(SqlConnection)?

Ronen

Miha Markic said:
Hi RA;

Try this:
oleDbConnection1.Open();

DataTable schemaTable =
oleDbConnection1.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,

new object[] {null, null, "YourTableName"});

oleDbConnection1.Close();

It stores all information you need for all columns into schemaTable
DataTable.

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com

RA said:
Hi

Is it possible to dynamicaly get the table columns and their data type and
size from sql server database? If not then how does the designed in vs does
this when you drug and drop a data adapter?

Thanks,
Ronen
 
Back
Top