How do I list all the queries in a MS Access file using OleDB in C#?

帅比萌擦擦* 提交于 2019-12-02 01:40:42

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

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

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

SELECT MSysObjects.Name
FROM MSysObjects
WHERE type = 5

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

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!