S
sourabh
Hi
I want to read a Database using ADO.Net and get the list of all Tables in it
and all the columns along with the Data Type of each from each table.
Using GetOleDbSchemaTable i am able to get the tables and columns but the
datatype is displayed as an integer. Any idea how i can get the Data Type
for the columns.
Here's what i am doing.
//Query for getting only the user tables
dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new
object[]{null,null,null,"TABLE"} );
//for each table get the columns
for( int index = 0 ; index < dt.Rows.Count ; index ++)
{
Console.WriteLine( "{0}", dt.Rows[index]["TABLE_NAME"].ToString() );//,
dt.Rows[index][0].ToString() , dt.Rows[index][1].ToString()
,dt.Rows[index][3].ToString() );
restricts = new object[] {null, null, dt.Rows[index]["TABLE_NAME"], null};
dbFields = conn.GetOleDbSchemaTable ( OleDbSchemaGuid.Columns, restricts);
for( int indexCol = 0 ; indexCol < dbFields.Rows.Count ; indexCol ++)
{
Console.Write( "{0},{1} |",
dbFields.Rows[indexCol]["COLUMN_NAME"].ToString() ,
dbFields.Rows[indexCol]["DATA_TYPE"].ToString() );
}
Console.WriteLine("\n");
}
}
Thanks
Sourabh
I want to read a Database using ADO.Net and get the list of all Tables in it
and all the columns along with the Data Type of each from each table.
Using GetOleDbSchemaTable i am able to get the tables and columns but the
datatype is displayed as an integer. Any idea how i can get the Data Type
for the columns.
Here's what i am doing.
//Query for getting only the user tables
dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new
object[]{null,null,null,"TABLE"} );
//for each table get the columns
for( int index = 0 ; index < dt.Rows.Count ; index ++)
{
Console.WriteLine( "{0}", dt.Rows[index]["TABLE_NAME"].ToString() );//,
dt.Rows[index][0].ToString() , dt.Rows[index][1].ToString()
,dt.Rows[index][3].ToString() );
restricts = new object[] {null, null, dt.Rows[index]["TABLE_NAME"], null};
dbFields = conn.GetOleDbSchemaTable ( OleDbSchemaGuid.Columns, restricts);
for( int indexCol = 0 ; indexCol < dbFields.Rows.Count ; indexCol ++)
{
Console.Write( "{0},{1} |",
dbFields.Rows[indexCol]["COLUMN_NAME"].ToString() ,
dbFields.Rows[indexCol]["DATA_TYPE"].ToString() );
}
Console.WriteLine("\n");
}
}
Thanks
Sourabh