使用:
查询Access 2000数据库时schemaTable = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Indexes, New Object() {Nothing, Nothing, tableName})
cn
是有效且开放的连接,schemaTable
始终包含零行,尽管tableName
指定了多个索引。
此文档({3}}建议MS Access提供此信息。
是什么给出了?
答案 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();
}