GetOleDbSchemaTable(OleDbSchemaGuid.Indexes,...)总是返回零行访问数据库

时间:2013-06-19 12:58:13

标签: vb.net ms-access oledb

使用:

查询Access 2000数据库时
schemaTable = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Indexes, New Object() {Nothing, Nothing, tableName})

cn是有效且开放的连接,schemaTable始终包含零行,尽管tableName指定了多个索引。

此文档({3}}建议MS Access提供此信息。

是什么给出了?

1 个答案:

答案 0 :(得分:2)

在检索.Indexes时,似乎限制数组的第三个成员对应于索引名称,而不是名称。因此,要检索给定表的索引,我们需要检索所有索引(没有限制),然后筛选出我们不想要的索引。

以下C#代码对我有用:

using (OleDbConnection con = new OleDbConnection())
{
    con.ConnectionString = myConnectionString;
    con.Open();
    object[] restrictions = new object[3];
    System.Data.DataTable table = con.GetOleDbSchemaTable(OleDbSchemaGuid.Indexes, restrictions);

    // Display the contents of the table.
    foreach (System.Data.DataRow row in table.Rows)
    {
        string tableName = row[2].ToString();
        if (tableName == "Clients")
        {
            foreach (System.Data.DataColumn col in table.Columns)
            {
                Console.WriteLine("{0} = {1}",
                  col.ColumnName, row[col]);
            }
            Console.WriteLine("============================");
        }
    }
    con.Close();
}
相关问题