vb 把access数据库中的数据在listbox中显示出来

2024-11-23 02:24:45
推荐回答(2个)
回答1:

首先,添加引用:

工程->引用->Microsoft ActiveX Data Object 2.0 Library

其次,添加代码,参考如下:

Private Sub Form_Load()

Dim conn As New ADODB.Connection

conn.Provider = "Microsoft.Jet.OleDB.4.0"
conn.Open "D:\学生信息.mdb"

Set rs = conn.Execute("您的学生信息表名")
conn.Cancel

Do Until rs.EOF
List1.AddItem rs("表中的中文字段名")
list2.AddItem rs("表中的英文字段名")
rs.MoveNext
Loop

conn.Close

End Sub

回答2:

dim cnn as new adodb.connection

dim rs as new adodb.recordset

cnn.open ....
rs.open "select * from tb ",cnn
do until rs.eof
list1.additem rs("english")
list2.additem rs("chinese")
rs.movenext
loop
rs.close