获取数据库内部的查询名称(VB.Net)

时间:2019-03-12 16:05:52

标签: vb.net ms-access

我有一个包含多个查询对象的数据库,我试图从Visual Studio中执行所有查询,但是为此,我需要每个查询的名称。 有什么方法可以从Visual Studio中获取数据库中所有查询的名称?

1 个答案:

答案 0 :(得分:1)

我能够使用Andrew建议的QueryDef对象将所有查询名称打印到ListBox中,以下是我使用的代码:

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