2010-11-20 97 views
0

有人可以告訴我如何將vb.net 2010連接到ms訪問數據庫以獲取數據並將其顯示在我現在正在執行的vb.net應用程序中。我的項目是我正在用vb.net做字典應用程序,所以每次我在搜索框中輸入新單詞時,我都希望vb.net從ms訪問中獲取定義並將其顯示在應用程序中。VB.NET 2010連接到ms訪問數據庫

和代碼段將是巨大的或教程

+4

可能重複:http://stackoverflow.com/questions/2365463/gathering-data-from-access-database – Fionnuala 2010-11-20 22:34:42

+0

這看起來像它已經被在這裏回答:http://stackoverflow.com/questions/2365463/gathering-data-from-access-database – 2010-11-22 20:09:13

回答

5
'Grabs data from a table and posts it into a ListView 

Dim Table_ As String = "Table1" 
Dim query As String = "SELECT * FROM " & Table_ 
Dim MDBConnString_ As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=TestDatabase.mdb;" 
Dim ds As New DataSet 
Dim cnn As OleDbConnection = New OleDbConnection(MDBConnString_) 

cnn.Open() 
Dim cmd As New OleDbCommand(query, cnn) 
Dim da As New OleDbDataAdapter(cmd) 
da.Fill(ds, Table_) 
cnn.Close() 

Dim t1 As DataTable = ds.Tables(Table_) 
Dim row As DataRow 
Dim Item(2) As String 

For Each row In t1.Rows 
    Item(0) = row(0) 
    Item(1) = row(1) 
    Dim NextListItem As New ListViewItem(Item) 

    ListView1.Items.Add(NextListItem) 
Next