将 ms access accdb 数据库的表名存储到 vb.net 中的数组中

store names of tables of a ms access accdb database into array in vb.net

我正在尝试获取 MS 访问数据库的所有表的名称并将其存储在一个数组中。有什么办法吗?或对此进行修改,我复制了这段代码,所以我不知道它是干什么用的

    con1.Open()
    Dim Restrictions() As String = {Nothing, Nothing, "Table1", Nothing}
    Dim CollectionName As String = "Columns"
    Dim dt As DataTable = con1.GetSchema(CollectionName, Restrictions)
    For Each TableRow As DataRow In dt.Rows
        Console.WriteLine(TableRow.Item("COLUMN_NAME").ToString)
    Next
    con1.Close()

要在您的数据库中获取所有 table 的名称,您应该使用包含 4 个 Nothing 值的限制和一个名为 TABLES 的集合。

con1.Open()

' No filter on the returned values
Dim Restrictions() As String = {Nothing, Nothing, Nothing, Nothing}

' Just interested in the TABLES collection
Dim CollectionName As String = "TABLES"

' Get the datatable with informations about the tables in the current db
Dim dt As DataTable = con1.GetSchema(CollectionName, Restrictions)
con.Close()

现在将所有内容传递回您可以使用的字符串数组中的调用代码

Dim names = dt.Rows.Cast(Of DataRow).Select(Function(x) x("TABLE_NAME")).ToArray()
return names