How can I get a list of tables in an Access (Jet) database?

前端 未结 4 1942
不思量自难忘°
不思量自难忘° 2020-12-16 17:18

I need to see if a table exists in an Access database used by my c# program. Is know there are SQL commands for other databases that will return a list of tables. Is there s

4条回答
  •  生来不讨喜
    2020-12-16 18:03

    that one worked for me

    using (OleDbConnection con = new OleDbConnection(connectionString))
                {
                    con.Open();
                    DataTable dt = con.GetSchema("Tables");
                    var selectNames = dt.Rows.Cast().Where(c => !c["TABLE_NAME"].ToString().Contains("MSys")).ToArray();
                    foreach (var item in selectNames)
                    {
                         // add names to comboBox
                        comboBox1.Items.Add(item["TABLE_NAME"]);
                    }
                }
    

提交回复
热议问题