Functionality for reading Database tables' schema using ADO.Net connection
Code can be downloaded here: Download
public DataTable GetTables(string strConnection)
{
//Create connectionstring
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(strConnection);
SqlConnection con = null;
DataTable dtTables = new DataTable();
try
{
con = new SqlConnection(builder.ConnectionString);
con.Open();
//Get the Schema for the tables
dtTables = con.GetSchema(SqlClientMetaDataCollectionNames.Tables, new string[] { null, null, null, "BASE TABLE" });
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (con != null)
{
con.Dispose();
}
}
return dtTables;
}
No comments:
Post a Comment