gpt4 book ai didi

c# - 检查 MS Access 数据库表,如果不存在则创建它

转载 作者:太空狗 更新时间:2023-10-29 17:28:51 25 4
gpt4 key购买 nike

如何以编程方式检查 MS Access 数据库表,如果不存在则创建它?

最佳答案

您可以遍历表名来检查特定表。请参阅以下代码以获取表名称。

        string connectionstring = "Your connection string";
string[] restrictionValues = new string[4]{null,null,null,"TABLE"};
OleDbConnection oleDbCon = new OleDbConnection(connectionString);
List<string> tableNames = new List<string>();

try
{
oleDbCon.Open();
DataTable schemaInformation = oleDbCon.GetSchema("Tables", restrictionValues);

foreach (DataRow row in schemaInformation.Rows)
{
tableNames.Add(row.ItemArray[2].ToString());
}
}
finally
{
oleDbCon.Close();
}

关于c# - 检查 MS Access 数据库表,如果不存在则创建它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4793549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com