Solved

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

Posted on 2011-03-09
5
464 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
  • 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

770 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