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?
-
Search about OleDb.Connection.GetSchema.Steve– Steve2019-03-12 16:09:18 +00:00Commented Mar 12, 2019 at 16:09
-
Are you talking about Views?djv– djv2019-03-12 16:32:57 +00:00Commented 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.Andrew Morton– Andrew Morton2019-03-12 16:44:08 +00:00Commented 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)Fernando– Fernando2019-03-12 17:10:56 +00:00Commented 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 itFernando– Fernando2019-03-12 17:13:34 +00:00Commented Mar 12, 2019 at 17:13
|
Show 2 more comments
1 Answer
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