您可以检查表中的项目数:
using(MyDataContext db = new MyDataContext(strConnectionString))
{
if (db.DatabaseExists() == false)
{
db.CreateDatabase();
}
if(db.Table1.Count() == 0) MessageBox.Show("Table is empty");
}
您还可以执行查询以获取表列表:
using (SqlConnection connection = new SqlConnection(strConnectionString))
{
connection.Open();
DataTable schema = connection.GetSchema("Tables");
List<string> TableNames = new List<string>();
foreach (DataRow row in schema.Rows)
{
TableNames.Add(row[2].ToString());
}
if(TableNames.Count == 0) MessageBox.Show("No table exists in the database.");
}