如何在 C# 中使用 OleDB 列出 MS Access 文件中的所有查询?

发布于 2024-07-11 03:35:53 字数 233 浏览 5 评论 0原文

我有一个包含 200 个查询的 Access 2003 文件,我想打印出它们在 SQL 中的表示形式。 我可以使用设计视图查看每个查询并将其剪切并粘贴到文件中,但这很乏味。 另外,我可能需要在其他 Access 文件上再次执行此操作,因此我肯定想编写一个程序来执行此操作。

Access 数据库中的查询存储在哪里? 我找不到任何说明如何获取它们的内容。 我对 Access 不熟悉,所以我很感激任何指点。 谢谢!

I have an Access 2003 file that contains 200 queries, and I want to print out their representation in SQL. I can use Design View to look at each query and cut and paste it to a file, but that's tedious. Also, I may have to do this again on other Access files, so I definitely want to write a program to do it.

Where are queries stored an Access db? I can't find anything saying how to get at them. I'm unfamiliar with Access, so I'd appreciate any pointers. Thanks!

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

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

发布评论

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

评论(4

情痴 2024-07-18 03:35:53

过程就是您要查找的内容:

OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();

DataTable queries = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Procedures, null);

conn.Close();

这将为您提供一个包含以下列(以及其他列)的 DataTable:

PROCEDURE_NAME:查询的名称

PROCEDURE_DEFINITION:SQL 定义

因此,您可以像这样循环遍历该表:

foreach(DataRow row in queries.Rows)
{
    // Do what you want with the values here
    queryName = row["PROCEDURE_NAME"].ToString();
    sql = row["PROCEDURE_DEFINITION"].ToString();
}

Procedures are what you're looking for:

OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();

DataTable queries = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Procedures, null);

conn.Close();

This will give you a DataTable with the following columns in it (among others):

PROCEDURE_NAME: Name of the query

PROCEDURE_DEFINITION: SQL definition

So you can loop through the table like so:

foreach(DataRow row in queries.Rows)
{
    // Do what you want with the values here
    queryName = row["PROCEDURE_NAME"].ToString();
    sql = row["PROCEDURE_DEFINITION"].ToString();
}
煮酒 2024-07-18 03:35:53

您可以使用 OleDbConnection 的 GetSchema 方法以及 Remou 发布的有关 ADO 架构的内容将其放在一起

哎呀忘记了链接:MSDN

you can put this together using the OleDbConnection's GetSchema method along with what Remou posted with regards to the ADO Schemas

oops forgot link: MSDN

伤感在游骋 2024-07-18 03:35:53

如果您想手动进行快速查询。

SELECT MSysObjects.Name
FROM MSysObjects
WHERE type = 5

In case you wanted to do a quick query by hand.

SELECT MSysObjects.Name
FROM MSysObjects
WHERE type = 5
余罪 2024-07-18 03:35:53

不是 C# 语言,但可能是一个不错的起点:

http://www.datastrat.com /Code/DocDatabase.txt

Not in C#, but may be a good place to start:

http://www.datastrat.com/Code/DocDatabase.txt

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