DataRow[] rows = dt.Select(); for (int i = 0; i < rows.Length; i++) { if (!rows[i]["TABLE_NAME"].ToString().Contains("MSys")) //Don't include all the system tables in Access { tempList.Add(rows[i]["TABLE_NAME"].ToString()); } } return tempList.IndexOf(TableName)>=0; }
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Is it possible to check existence of object before accesing?
Sep 15, 2011 02:25 AM|LINK
Hello,
To find out whether a table name is included in an Access db, you can also try this:
public boolean ContainsTable (string OleDbConnectionStr,string TableName)
{
List<string> tempList = new List<string>();
OleDbConnection oleConn = new
OleDbConnection(OleDbConnectionStr);
oleConn.Open();
DataTable dt = oleConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
oleConn.Close();
DataRow[] rows = dt.Select();
for (int i = 0; i < rows.Length; i++)
{
if (!rows[i]["TABLE_NAME"].ToString().Contains("MSys")) //Don't include all the system tables in Access
{
tempList.Add(rows[i]["TABLE_NAME"].ToString());
}
}
return tempList.IndexOf(TableName)>=0;
}