Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-09
5
Medium Priority
?
508 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 2000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

721 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