PWNettle Posted June 17, 2004 Posted June 17, 2004 (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 June 17, 2004 by PWNettle Quote
pelikan Posted June 17, 2004 Posted June 17, 2004 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 Quote IN PARVUM MULTUM
PWNettle Posted June 17, 2004 Author Posted June 17, 2004 Thanks for the additional ideas. I think I'll stick with #1 and end up making some classes to wrap the column info I'm interested in. Paul Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.