【问题标题】:GetOleDbSchemaTable(OleDbSchemaGuid.Indexes, ...) always returning zero rows access databaseGetOleDbSchemaTable(OleDbSchemaGuid.Indexes, ...) 总是返回零行访问数据库
【发布时间】:2013-06-19 12:58:12
【问题描述】:

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

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

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

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

什么给了?

【问题讨论】:

    标签: vb.net ms-access oledb


    【解决方案1】:

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

    以下 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();
    }
    

    【讨论】:

    • 感谢您,很快就会尝试一下。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多