How do I get a list of tables from the database

  • Thread starter Thread starter Chris Botha
  • Start date Start date
C

Chris Botha

With ADO, one could use the ADOX.Catalog to get tables in a database. How do
I do it with ADO.NET?

Thanks.
 
Hi Chris,

You can use SQL's built in SPs to do this.

Call: sp_help on the database in question then filter the object_type field
on "user_table".

You can load the results from sp_help into a dataset then run through the
table looking for the user_table entries.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/wwHelp
 
Or look at systables?

--
____________________________________
Bill Vaughn
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
I know, it will work for SQL Server, but my back-end databases can be SQL
Server, MS Access and Oracle as well. ADOX works for all three, I was
hoping for something similar in ADO.NET that will be database independent.
 
Here's what I use with an OleDBconnection in C#.

// cn is your ADO.NET OleDBconnection
DataTable schemaTable;

schemaTable =
cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
new object[] {null, null, null, "TABLE"});

// Show each table name
foreach (DataRow row in schemaTable.Rows)
MessageBox.Show(row["TABLE_NAME"].ToString();
 
It works for SQL Server and MS Access, I'll try it tomorrow at work for
Oracle. Thanks.

Bob Costello said:
Here's what I use with an OleDBconnection in C#.

// cn is your ADO.NET OleDBconnection
DataTable schemaTable;

schemaTable =
cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
new object[] {null, null, null, "TABLE"});

// Show each table name
foreach (DataRow row in schemaTable.Rows)
MessageBox.Show(row["TABLE_NAME"].ToString();


-----Original Message-----
With ADO, one could use the ADOX.Catalog to get tables in a database. How do
I do it with ADO.NET?

Thanks.


.
 
you gotta tlbimp ADOX to do this. I believe this works, but it has been a
couple of years since I looked at it.
-D
 
Back
Top