用vb.net怎么连接数据库?a列显示在ListBox1,b列显示在ListBox2中?求代码,实
用vb.net怎么连接数据库?a列显示在ListBox1,b列显示在ListBox2中?求代码,实例...
用vb.net怎么连接数据库?a列显示在ListBox1,b列显示在ListBox2中?求代码,实例
展开
2个回答
展开全部
Public Class Form1
Private Function BindData(ByVal str As String) As DataTable
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\project\office\test.accdb")
Dim mtab As New DataTable
Dim adp As New OleDb.OleDbDataAdapter(str, conn)
mtab.Clear()
conn.Open()
adp.Fill(mtab)
conn.Close()
Return mtab
End Function
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim t As New DataTable
t = BindData("select * from Maintab")
ListBox1.DataSource = t
ListBox2.DataSource = t
ListBox1.DisplayMember = "a"
ListBox2.DisplayMember = "b"
End Sub
End Class
Private Function BindData(ByVal str As String) As DataTable
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\project\office\test.accdb")
Dim mtab As New DataTable
Dim adp As New OleDb.OleDbDataAdapter(str, conn)
mtab.Clear()
conn.Open()
adp.Fill(mtab)
conn.Close()
Return mtab
End Function
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim t As New DataTable
t = BindData("select * from Maintab")
ListBox1.DataSource = t
ListBox2.DataSource = t
ListBox1.DisplayMember = "a"
ListBox2.DisplayMember = "b"
End Sub
End Class
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
能
追问
怎么写
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询