Tuesday, November 3, 2009

Get Database Schema

If you want to list the tables of a database and columns of a table you may use the "GetSchema" method of System.Data.Common.DbConnection class.
It works on both MS Sql Server 200 and 2005. I did not try on other servers.

Sample Code

DbConnection con = new OleDbConnection(connetionString);
DataTable tables =
con.GetSchema("TABLES", new string[] {null, null, null, "BASE TABLE" });
DataTable columns =
con.GetSchema("COLUMNS", new string[] {"CustomerTable", null, null });

No comments:

Post a Comment