直接上代码
private bool IsTableExists(DataTable dataTable, string tableName)
{
// 遍历 DataTable 中的每一行,判断 TABLE_NAME 列的值是否等于指定的表名
foreach (DataRow row in dataTable.Rows)
{
object tableNameValue = row["TABLE_NAME"];
if (tableNameValue != null && tableNameValue.ToString().Equals(tableName, StringComparison.OrdinalIgnoreCase))
{
return true; // 找到匹配的表名
}
}
return false; // 未找到匹配的表名
}
private bool TableExists(string tableName)
{
if (conn.conn.State == ConnectionState.Closed)
conn.conn.Open();
DataTable schemaTable = conn.conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
new object[] { null, null, null, "TABLE" });
return IsTableExists(schemaTable, tableName);
}