. Net is often used to read the table structure in the Access database, you can consider the convenient GetOleDbSchemaTable
The schema table is returned in the form of a able, which is in the same format as the ole db schema row set specified by the schema parameter. Use the restrictions parameter to filter the rows to be returned to the able (for example, by specifying the table name, type, owner, or schema constraints ). When passing a value to an array, include an empty string or null for an array element that does not contain a value. If an empty array is passed to restrictions, all rows (one row in each table) are returned in the default order. The values in the array correspond to the order of columns in the source table and DataTable. Each element in the restricted array is compared with the content of the corresponding column in the schema row set. For example, compare the first element in the array with the first column in the row set. If the limit element is not null, only the rows in the schema row set that exactly match the limit value are added to the result able.
The following is an example provided by MSDN, which returns the list of tables in the database.
Public Function GetSchemaTable (ByVal connectionString As String )_
As DataTable
Using connection As New OleDbConnection (connectionString)
Connection. Open ()
Dim schemaTable As DataTable = _
Connection. GetOleDbSchemaTable (OleDbSchemaGuid. Tables ,_
New Object () {Nothing, "TABLE "})
Return schemaTable
End Using
End Function
If you need to return the field structure of a table, you can modify it a little. For details, refer to the entries under OleDbSchemaGuid in MSDN. The following is the test code:
Dim conn As String = "Provider = Microsoft. Jet. OLEDB.4.0; Data Source = D: \ Backup \ My Documents \ order 1.mdb; Persist Security Info = False"
Using connection As New OleDbConnection (conn)
Connection. Open ()
Dim schemaTable As DataTable = _
Connection. GetOleDbSchemaTable (OleDbSchemaGuid. Columns ,_
New Object () {Nothing, Nothing, "table 1", Nothing })
DataGridView1.DataSource = schemaTable will display the returned table in DataGridView1
End Using