且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 C# 在 MS Access 中查找表

更新时间:2023-02-07 23:20:28

根据您连接到 ms-access 文件的方式,您可以以不同的方式读取表和列/字段名称:

Depending on the way you are connecting to the ms-access fiele, you can read tables and column/field names in different ways:

  1. 通过 OLEDB 连接:您可以使用 ADOX 对象集合并读取数据库中可用的表、列、索引等
  2. 使用 ODBC 连接,您可以列出 MS-ACCESS 系统表,打开每个表上的记录集,然后读取所有字段名称.可以使用以下 SQL 指令列出表:

  1. With an OLEDB connecion: you can use the ADOX Objects collection and read tables, columns, indexes, etc available in the database
  2. With an ODBC connection, you can list the MS-ACCESS system tables, open a recordset on each table, and then read all field names. Tables can be listed with the following SQL instruction:

SELECT name FROM MSysObjects WHERE type = 1

SELECT name FROM MSysObjects WHERE type = 1

在所有情况下,一旦通过记录集打开表,您可以通过以下方式读取其字段名称循环记录集对象的字段集合

In all case, once a table is opened through a recordset, you can read its field names by looping on the fields collection of the recordset object