将所有表格都添加到DataTable []

时间:2015-09-26 13:50:46

标签: c# ms-access oledb

我有一个包含多个表的Access DB。我需要将它们全部转移到DataTable数组。

这就是我所拥有的:

using (OleDbConnection conn = new OleDbConnection(connStr))
{
    conn.Open();
    tables = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
}

tables是:public DataTable tables = null;

1 个答案:

答案 0 :(得分:0)

解决方案是使用OleDbDataAdapterDataSet

    public DataSet tables = new DataSet();
    public OleDbDataAdapter adapter;

    public BusLogic()
    {
        using (OleDbConnection conn = new OleDbConnection(connStr))
        {
            conn.Open();

            adapter = new OleDbDataAdapter("SELECT * FROM City", conn);
            adapter.Fill(tables, "Cities");
        }
    }