Check for MS Access database table if not exist create it

后端 未结 5 1744
失恋的感觉
失恋的感觉 2020-12-20 14:55

How do you programmatically check for MS Access database table, if not exist then create it?

5条回答
  •  孤城傲影
    2020-12-20 15:35

    You could iterate though the table names to check for a specific table. See the below code to get the table names.

            string connectionstring = "Your connection string";
            string[] restrictionValues = new string[4]{null,null,null,"TABLE"};
            OleDbConnection oleDbCon = new OleDbConnection(connectionString);
            List tableNames = new List();
    
            try
            {
                oleDbCon.Open();
                DataTable schemaInformation = oleDbCon.GetSchema("Tables", restrictionValues);
    
                foreach (DataRow row in schemaInformation.Rows)
                {
                   tableNames.Add(row.ItemArray[2].ToString());
                }
            }
            finally
            {
                oleDbCon.Close();
            }           
    

提交回复
热议问题