0

I have a database with multiple query objects inside of it, I am trying to execute all of them from visual studio but to do so I need the name of each query. Is there any way to get the name of all the queries inside a database, from within visual studio?

7
  • Search about OleDb.Connection.GetSchema. Commented Mar 12, 2019 at 16:09
  • Are you talking about Views? Commented Mar 12, 2019 at 16:32
  • If you mean QueryDef objects and running a program created in VS rather than using VS directly, there seems to be code to do that in the QueryDef object (DAO) documentation. Commented Mar 12, 2019 at 16:44
  • Steve, the GetSchema has only been useful the get the list of 'Table' or 'Make Table Query' objects but I haven't been successful to extract the name of 'Select Query' type objects. This is the code I am using for that: restrictions(3) = "View" Tables = cn.GetSchema("Tables", restrictions) Commented Mar 12, 2019 at 17:10
  • Andrew, do you know how I can use the QueryDef on vb.net? Because I get a Type 'QueryDef' is not defined, error when I try to use it Commented Mar 12, 2019 at 17:13

1 Answer 1

1

I was able to print all the query names into a ListBox using QueryDef object as Andrew suggested, below is the code I used:

Imports Microsoft.Office.Interop.Access.Dao
Private Sub UpdateList(PathDB As String, List As ListBox)
    Dim db As Database
    Dim qdfLoop As QueryDef
    Dim DAOBEngine As New DBEngine()
    'Old list is cleared
    List.Items.Clear()
    'Connection to the database is created
    db = DAOBEngine.OpenDatabase(PathDB, False, False, "")
    'Each query on the database is added to the ListBox
    For Each qdfLoop In db.QueryDefs
        List.Items.Add(qdfLoop.Name)
    Next
    'Connection to the database is closed
    db.Close()
End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.