There may be times when you'll want to interrogate your database and find information about it's schema like table names, table definitions etc. ADO.NET gives us two very cool ways to accomplish this. Most of the time, when you call one of SqlClient's methods or properties, you can do the same with OleDb, Odbc etc. Most of the time, not always. In this instance however, the approach is fundamentally different. If you are using SqlClient, you simply query Sql Server's Information_Schema and restrict the results so that Table_Type = BASE TABLE. On the other hand, with OleDb (Access comes to mind on this) you open a connection, and then call its OleDbConnection.GetOleDbSchematable method.
So, assuming that you are using SqlClient, this is basically how you do it.
VB.NET
| Dim cn as New SqlConnection("YourConnectionStringHere") Dim da as New SqlDataAdapter("SELECT * FROM Information_Schema.Tables where Table_Type = 'BASE TABLE'", cn) Dim dt as New DataTable da.Fill(dt) |
| SqlConnection cn = new SqlConnection("YourConnectionStringHere"); SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Information_Schema.Tables where Table_Type = 'BASE TABLE'", cn"); DataTable dt = new DataTable(); da.Fill(dt); |
| Dim cn as New OleDbConnection("YourConnectionStringHere") Dim dt as New DataTable cn.Open dt = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {nothing, nothing, nothing, "Table"}) cn.Close |
| OleDbConnection cn = new OleDbConnection("YourConnectionStringHere"); cn.Open(); DataTable dt = new DataTable(); dt = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new Object[] {null, null, null, "Table"}); cn.Close |