Dave,
The only problem I found with using the
OleDbDataReader.GetSchemaTable() method is that you can't
find the type for a specific field by name like this:
DataTable schemTbl = dataReader.GetSchemaTable();
DataRow row = schemTbl.Rows["age"]; //can't do this
Console.WriteLine(row["DataType"]);
Actually, with a slight change to the code, there are a
couple different ways you can do this.
You can locate a row in the schema table based on the
resultset's column name by setting the schema table's primary key:
schemTbl.PrimaryKey = new DataColumn[]
{schemTbl.Columns["ColumnName"]};
DataRow row = schemTbl.Rows.Find(strColumnName);
Console.WriteLine(row["DataType"]);
Or you could ask the DataReader for a column's ordinal in
the resultset, and use that information to locate the row in the
schema table:
int intColumnIndex = dataReader.GetOrdinal(strColumnName);
DataRow row = schemTbl.Rows[intColumnIndex];
Console.WriteLine(row["DataType"]);
David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2003 Microsoft Corporation. All rights reserved.