VB.NET 2010连接ms access数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4234941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 15:09:17  来源:igfitidea点击:

VB.NET 2010 to connect to ms access database

vb.netms-access

提问by user484831

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 right 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.

有人可以告诉我如何将 vb.net 2010 连接到 ms access 数据库以获取数据并将其显示在我现在正在做的 vb.net 应用程序中。我的项目是我正在用 vb.net 做字典应用程序,所以每次我在搜索框中输入新词时,我都希望 vb.net 从 ms access 获取定义并将其显示在应用程序中。

And code snippet would be great or tutorial

和代码片段会很棒或教程

回答by Kyle

'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