Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

How would I go about getting table and field information for a SQL Server database?

 

Point me in the right direction and I can figure it out - my searching isn't yielding any results. I'm looking for something similar to what ADOX provides for VB6.

 

My language of choice is C# (for code examples or linked resources).

 

EDIT:

 

I figured out one way to do it - using DataTables in conjunction with the oledb connection's GetOleDbSchemaTable method - as I finally found something relative in MSDN. However, the info you get for table columns is very raw and requires interpretation. To really use the info I'm getting I'd probably end up writing some classes to better present and organize the raw data. It seems like something like this should already exist (MS provided in the framework, not user-built) - so if anyone knows of such a thing let me know!

 

Paul

Edited by PWNettle
Posted

there are lots of possible ways to get schema metadata.

 

1. As you stated GetOleDbSchemaTable is one way. The nice thing about this is that it is generic, will work with any provider that is SQL compliant - Access, Excel, SQL Server etc.

 

2. You could query SQL Server's INFORMATION_SCHEMA tables (thats actually what GetOleDBSchemaTable does) choose just the columns you need.

 

3. The only thing like ADOX for SQL Server is the COM library SQL-DMO, with this, not only do you get all metadata, but you can completely administer the server - probably overkill in most cases.

 

4. You probably already know about getting specific schema info thru the DataAdapter.

(FillSchema() or MissingSchemaAction.AddWithKey).

 

5. with VS you could use SQLXML to stream out metadata in XML format.

 

It would take a little work, but you could set up a Strongly Typed DataSet from the GetOleDbSchemaTable tables - then tailor the class produced by Xsd.exe

IN PARVUM MULTUM

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...