vb中如何让access中某一字段的内容显示在listbox中?
比如如何在点击command1之后在listbox中显示出c:\student.mdb中表stu姓名字段中的内容?请高手指教...
比如如何在点击command1之后在listbox中显示出c:\student.mdb中 表stu 姓名字段中的内容?
请高手指教 展开
请高手指教 展开
2个回答
展开全部
'首先要在工程引用中引用:microsoft activex data objects 2.5 library 然后复制下面代码:
Dim Conn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Dim have As Boolean
Private Sub Command1_Click()
List1.Clear
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\student.mdb;Persist Security Info=True;Jet OLEDB:Database Password="
SQL = "select * from stu"
Rs.Open SQL, Conn, 1, 3
Do While Rs.EOF = True
List1.AddItem "" & Rs("姓名")
Rs.movenext
Loop
Conn.Close
Set Rs = Nothing
Set Conn = Nothing
End Sub
Dim Conn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Dim have As Boolean
Private Sub Command1_Click()
List1.Clear
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\student.mdb;Persist Security Info=True;Jet OLEDB:Database Password="
SQL = "select * from stu"
Rs.Open SQL, Conn, 1, 3
Do While Rs.EOF = True
List1.AddItem "" & Rs("姓名")
Rs.movenext
Loop
Conn.Close
Set Rs = Nothing
Set Conn = Nothing
End Sub
引用ludecai223的回答:
'首先要在工程引用中引用:microsoft activex data objects 2.5 library 然后复制下面代码:
Dim Conn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Dim have As Boolean
Private Sub Command1_Click()
List1.Clear
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\student.mdb;Persist Security Info=True;Jet OLEDB:Database Password="
SQL = "select * from stu"
Rs.Open SQL, Conn, 1, 3
Do While Rs.EOF = True
List1.AddItem "" & Rs("姓名")
Rs.movenext
Loop
Conn.Close
Set Rs = Nothing
Set Conn = Nothing
End Sub
'首先要在工程引用中引用:microsoft activex data objects 2.5 library 然后复制下面代码:
Dim Conn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Dim have As Boolean
Private Sub Command1_Click()
List1.Clear
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\student.mdb;Persist Security Info=True;Jet OLEDB:Database Password="
SQL = "select * from stu"
Rs.Open SQL, Conn, 1, 3
Do While Rs.EOF = True
List1.AddItem "" & Rs("姓名")
Rs.movenext
Loop
Conn.Close
Set Rs = Nothing
Set Conn = Nothing
End Sub
展开全部
遍历过程中应是
Do While Rs.EOF=False才对
Do While Rs.EOF=False才对
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询