Here's how I do it:
cn = CreateConnection()
cn.Open()
' get list of tables
Dim myNull() As Object = {aNull, aNull, aNull, "TABLE"}
' cast connection so we can use GetOleDbSchemaTable method
dt = CType(cn,
OleDbConnection).GetOleDbSchemaTable(OleDbSchemaGuid.Tables, myNull)
Dim dr As DataRow
For Each dr In dt.Rows
TableList.Add(dr("TABLE_NAME"))
Next
' read table data
cmd.Connection = cn
For i = 0 To TableList.Count - 1
strTableName = TableList(i)
cmd.CommandText = "SELECT * FROM " & strTableName
myReader = cmd.ExecuteReader(CommandBehavior.KeyInfo)
dt = myReader.GetSchemaTable()
strPKList = ""
Dim fieldList As New ArrayList
For Each dRow In dt.Rows
aField.FieldName = dRow("ColumnName")
aField.OrdinalPosition = dRow("ColumnOrdinal")
aField.DataType = dRow("DataType")
aField.Size = dRow("ColumnSize")
fieldList.Add(aField)
If dRow("IsKey") Then
' remove the last ;
strPKList += dRow("ColumnName") & ";"
End If
Next
If Len(strPKList) > 1 Then
strPKList = strPKList.Remove(Len(strPKList) - 1, 1)
End If
TableFields.Add(strTableName, fieldList)
TablePrimaryKeys.Add(strTableName, strPKList)
myReader.Close()
Next
John