Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a list of available tables from an ODBC connection?

Tags:

c#

odbc

In Excel I can go to Data -> Import External Data -> Import Data... and then select the data source to use and then after I provide login information it gives me a list of tables. I would like to know how to get that list programmatically using C#.

like image 901
classicspage Avatar asked Dec 31 '09 17:12

classicspage


2 Answers

What type of data source are you interrogating? SQL Server? Access?

Look at this thread: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/bcf25d16-3ecd-427d-9ad2-57619d6b3691

Also documentation for the OdbcConnection.GetSchema Method here: http://msdn.microsoft.com/en-us/library/system.data.odbc.odbcconnection.getschema.aspx

This may work for you: OdbcConnection.GetSchema("Tables")

like image 166
Krip Avatar answered Oct 15 '22 10:10

Krip


Normally, you would have to be a bit more explicit to disregard system tables:

connection.GetSchema("Tables").AsEnumerable().Where(r => r.Field<string>("TABLE_TYPE") == "TABLE")
like image 44
Lars Michael Avatar answered Oct 15 '22 10:10

Lars Michael