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

前端 未结 4 1202
余生分开走
余生分开走 2021-01-21 21:12

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

相关标签:
4条回答
  • 2021-01-21 21:19

    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

    0 讨论(0)
  • 2021-01-21 21:25

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

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

    0 讨论(0)
  • 2021-01-21 21:31

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

    SELECT MSysObjects.Name
    FROM MSysObjects
    WHERE type = 5
    
    0 讨论(0)
  • 2021-01-21 21:44

    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();
    }
    
    0 讨论(0)
提交回复
热议问题