Oct 5, 2007

Get table Schema using the sqlreader

conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader reader = cmd.ExecuteReader();

DataTable schema = reader.GetSchemaTable();

foreach (DataRow row in schema.Rows)
{
foreach (DataColumn col in schema.Columns){
Console.WriteLine(col.ColumnName + " = " + row[col]);
Console.WriteLine("Null value allowed: " + col.AllowDBNull);
}
}
reader.Close();