2014-07-21 66 views
-2

我想選擇指標列表,並把它放在一個DataTable中viusal基礎和使用OLEDB IAM連接到2002-2003數據庫格式(.mdb)中如何從MS接入選擇指數從特定表2007

一樣,

Dim con as new oledb.oledbconnection 
Dim conAdapter as oledb.oledbDataAdabter 
Dim Table as new datatable 

conn.ConnectionString = "Provider=Microsoft.jet.OLEDB.4.0; Data Source='MY DATABESE LOCATION';" 
conn = New OleDb.OleDbDataAdapter("SELECT * FROM 'what i want to select table1 indexes'", conn) 
connAdabter.fill(Table) 

感謝

回答

1

OleDbConnection有一個返回有關表,索引等模式信息的方法......

Dim connectionString = "Provider=Microsoft.jet.OLEDB.4.0; Data Source='MY DATABESE LOCATION';" 
Using con as new oledb.oledbconnection(connectionString) 
    con.Open() 
    Dim indexes = con.GetSchema("Indexes").Select("TABLE_NAME = 'yourTableNameHere'").CopyToDataTable() 
    For Each row in indexes.Rows 
     Console.WriteLine(row("INDEX_NAME")) 
     Console.WriteLine(row("COLUMN_NAME")) 
     Console.WriteLine(row("PRIMARY_KEY")) 
    Next 

End Using 

See MSDN OleDbConnection.GetSchema

+0

感謝非常非常有用的工作,我正在尋找月份 – user3772967