Use the below code to fetch the schema detail from the data base
string conString =
string query = "select * from tableName";
SqlConnection con = new SqlConnection(conString);
try
{
con.Open();
SqlCommand cmd = new SqlCommand(query, con);
SqlDataReader reader = cmd.ExecuteReader();
DataTable schema = reader.GetSchemaTable();
reader.Close();
}
catch(Exception e)
{
Console.WriteLine("Error Occurred: " + e);
}
finally
{
conn.Close();
}
Hope this will help you