Is it possible to use GetSchemaTable() to retrieve only column names?
I have been trying to retrieve Column names (only) using this method, is it possible.
DataTable table = myReader.GetSchemaTable();
foreach (DataRow myField in table.Rows)
{
foreach (DataColumn myProperty in table.Columns)
{
fileconnectiongrid.Rows.Add(myProperty.ColumnName + " = "
+ myField[myProperty].ToString());
}
}
This code retrieves a lot of table data unwanted, I only need a list containing
column names!:
You need to use
ExecuteReader(CommandBehavior.SchemaOnly)):SchemaOnly:
The column name is in the first column of every row. I don’t think that it’s possible to omit the other column informations like
ColumnOrdinal,ColumnSize,NumericPrecisionand so on since you cannot usereader.GetStringbut onlyreader.GetSchemaTablein this case.But your loop is incorrect if you only want the column names: