开发者

VB.NET 2010 to connect to ms access database

Can someone show me how to connect vb.net 2010 to ms access database to get the data and display it in vb.net application that I am doing righ开发者_开发技巧t now. My project is that I am doing dictionary application with vb.net so every time i put new word in search box, I want the vb.net to get the definition from ms access and display it in the application.

And code snippet would be great or tutorial


'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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜