Solved

I would like to return the schema of a Datatable using C#

Posted on 2011-03-09
5
491 Views
Last Modified: 2013-12-17
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
Comment
Question by:Mr_Shaw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 35082360
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 35082370
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
 

Author Comment

by:Mr_Shaw
ID: 35082404
Hi Dhaest,

I need to return a Table
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 35082538
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
 

Author Closing Comment

by:Mr_Shaw
ID: 35082695
thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question