C# / Access 从 Access 2003 获取主键

发布于 2024-07-26 02:32:03 字数 197 浏览 2 评论 0原文

我正在使用 OleDb 与 Access 数据库交互,我试图找出如何获取每个表的主键,但以这样的方式将它们与表关联起来。 换句话说,我不只是想要一个主键列名称的平面列表——我希望能够确定它们属于哪个表。

知道如何做到这一点吗? 我已使用 GetSchema() 方法来获取表的表,但该表的信息似乎不包含主键(或任何其他索引)。

I'm using OleDb to interact with an Access database, and I'm trying to find out how to get the primary keys of each table, but in such a way that they are associated with the tables. In other words, I don't just want a flat list of the primary key column names--I want to be able to determine which table they belong to.

Any idea how to do this? I've used the GetSchema() method to get a table of tables, but that table's information does not appear to include primary keys (or any other indexes, for that matter).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

在巴黎塔顶看东京樱花 2024-08-02 02:32:03

好的——做了一些列名的输出,并更好地理解了模式表的关联方式。

为此,请将字符串“Indexes”传递给 GetSchema() 方法。 索引表中的每条记录都包含表名以及索引是否为主键。

Ok--did a little outputting of column names and got a better understanding of how the schema tables are related.

To do this, pass the string "Indexes" to the GetSchema() method. Each record in the index table contains both the table name and whether or not the index is the primary key.

草莓酥 2024-08-02 02:32:03

我认为您的意思是,对于模式中的每个外键,您想要发现引用表的名称。 从快速谷歌看来,这可能是不可能的:

Microsoft Connect:DbConnection .GetSchema:无法获取外键列

...这很奇怪,因为使用 ADO 经典(COM,而不是 .NET)OpenSchema 方法就可以。

I think what you mean is that for each FOREIGN KEY in the schema you want to discover the name of the referenced table. From a quick google it seems this may not be possible:

Microsoft Connect: DbConnection.GetSchema: no ways to get foreign keys' columns

...which is strange because with ADO classic's (COM, not .NET) OpenSchema method you can.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文