Mr_Shaw
asked on
I would like to return the schema of a Datatable using C#
I would like to return the schema of a Datatable using C#
For example:
DataSet ds = new DataSet();
ap.Fill(ds);
return ds.Tables[0].GetSchema();
Is this possible
For example:
DataSet ds = new DataSet();
ap.Fill(ds);
return ds.Tables[0].GetSchema();
Is this possible
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Dhaest,
I need to return a Table
I need to return a Table
You can just execute one query that will return the data in a datatable
SqlConnection cn = new SqlConnection("PutYourConn ectionStri ngOverHere ");
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Information_Schema.Tables where Table_Type = 'BASE TABLE'", cn");
DataTable dt = new DataTable();
da.Fill(dt);
Now is dt filled with your information
SqlConnection cn = new SqlConnection("PutYourConn
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Information_Schema.Tables where Table_Type = 'BASE TABLE'", cn");
DataTable dt = new DataTable();
da.Fill(dt);
Now is dt filled with your information
ASKER
thanks.
DataTable dt=...;
foreach (DataColumn c in dt.Columns)
{
Console.WriteLine(c.Column
}