2013年6月12日 星期三

VB.NET Fields in an Access database table

參考引用:Fields in an Access database table
如何使用 GetOleDbSchemaTable 和 Visual Basic.NET 中擷取結構描述資訊
--
Module Module1
    'How to get a list of columns from an access database given a table name    
    Dim oleConn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\users.mdb")
    Dim restrictions() As String = {"", "", "userinfo", ""}
    Dim SchemaTable As DataTable
    Public Sub connect()
        oleConn.Open()
        SchemaTable = oleConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Columns, _
                    New Object() {Nothing, Nothing, Nothing, Nothing})
        Dim int As Integer
        For int = 0 To SchemaTable.Rows.Count - 1
            If SchemaTable.Rows(int)!TABLE_TYPE.ToString = "TABLE"
'EXCEPTION : Table is not part of table column
Then
                'Add items to list box
                Form1.comboselecttable.Items.Add(SchemaTable.Rows(int)!COLUMN_NAME.ToString())
            End If
            '// Get list of tables columns
        Next
        'Form1.comboselecttable.Items.Add(dbRet.Rows(0)!TABLE_NAME.ToString())
        '// dbRet will have a column name called "COLUMN_NAME" which will contain all the columns for the table
    End Sub
    Public Sub endconn()
        oleConn.Close()
    End Sub
End Module

沒有留言:

張貼留言