Один из способов сделать это - использовать OleDbCommand.ExecuteReader для считывания схемы каждой найденной таблицы.
OleDbConnection con = new OleDbConnection(connectionString);
DataSet tablesFromDB = new DataSet();
DataTable schemaTbl;
try
{
// Open the connection
con.Open();
object[] objArrRestrict = new object[] { null, null, null, "TABLE" };
// Get the table names from the database we're connected to
schemaTbl = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, objArrRestrict);
// Not sure if this is correct syntax...fix it if it isn't :)
String commandText = @"SELECT * FROM {0}";
// Get each table name that we just found and get the schema for that table.
foreach (DataRow row in schemaTbl)
{
DataTable dt = new DataTable();
OleDbCommand command = new OleDbCommand(String.Format(commandText, row["TABLE_NAME"] as String), con);
dt.Load(command.ExecuteReader(CommandBehavior.SchemaOnly));
tablesFromDB.Tables.Add(dt);
}
}
Таким образом, вы можете перебирать коллекцию DataTable DataSet и получать оба столбцаИмена и типы полей столбцов.
foreach (DataTable dt in tablesFromDB)
{
foreach (DataColumn dc in dt.Columns)
{
// Do something with the column names and types here
// dc.ColumnName is the column name for the current table
// dc.DataType.ToString() is the name of the type of data in the column
}
}
Возможно, есть лучший способ сделать это, но я думаю, что это только начало.