Solved

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

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now