Dim sConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;"
'Use the user-selected database file as the Data Source value.
Dim OpenFileDialog1 As New OpenFileDialog() '浏览mdb的位置
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
sConStr &= "Data Source=" & OpenFileDialog1.FileName & ";"
Dim conn As New System.Data.OleDb.OleDbConnection(sConStr)
conn.Open()
Dim dt As System.Data.DataTable = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Columns, _
New Object() {Nothing, Nothing, "table1"})
Dim i As Integer
For i = 0 To dt.Rows.Count - 1
Debug.WriteLine(dt.Rows(i).Item("Column_name"))
Next
End If
可以用判断来实现:
myconn2.Open(str2)
reordset = myconn2.OpenSchema(SchemaEnum.adSchemaTables)
Do Until reordset.EOF
If reordset("table_type").Value = "TABLE" Then
ComboBox1.Items.Add(reordset("table_name").Value)
End If
reordset.MoveNext()
Loop
reordset.Close()
myconn2.Close()