I'm trying to get the names of all tables of ms access database and store in a array. Is there any way to do that? or modification of this, I copied this code so I DONT KNOW WHAT IS IT FOR
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()
CodePudding user response:
To get all the table's names in your database you should use a restriction with 4 Nothing values and a collection named 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()
Now to pass everything back to the calling code in an array of strings you could use
Dim names = dt.Rows.Cast(Of DataRow).Select(Function(x) x("TABLE_NAME")).ToArray()
return names
