• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 514
  • Last Modified:

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
0
Mr_Shaw
Asked:
Mr_Shaw
  • 3
  • 2
1 Solution
 
DhaestCommented:
You can also just loop over your columns to get the information.

DataTable dt=...;
foreach (DataColumn c in dt.Columns)
{
  Console.WriteLine(c.ColumnName + " " + dt[c]);
}

0
 
Mr_ShawAuthor Commented:
Hi Dhaest,

I need to return a Table
0
 
DhaestCommented:
You can just execute one query that will return the data in a datatable

SqlConnection cn = new SqlConnection("PutYourConnectionStringOverHere");
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
0
 
Mr_ShawAuthor Commented:
thanks.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now