1

查询 Access 2000 数据库时,使用:

schemaTable = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Indexes, New Object() {Nothing, Nothing, tableName})

wherecn是一个有效且开放的连接,schemaTable总是包含零行,尽管tableName指定的有很多索引。

此文档(此处为http://msdn.microsoft.com/en-us/library/cc668764.aspx)建议 MS Access 提供此信息。

是什么赋予了?

4

1 回答 1

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();
}
于 2013-06-19T14:35:24.547 回答