怎么将数据库表中的数据显示在VB的listbox列表中

2024-11-22 17:48:51
推荐回答(2个)
回答1:

引用microsoft activex data object

dim cn as new adodb.connection
dim rs as new adodb.recordset
dim sqlconnectionstr as string
dim sqlsentence as string

sqlconnectionstr="Provider=SQLOLEDB.1;Password=数据库密码;Persist Security Info=True;User ID=sa;Initial Catalog=数据库对象名;Data Source=数据库地址"

sqlsentence=数据库检索语句

cn.connectionstring=sqlconnectionstr
cn.open
rs.open sql,cn,1,1

do while not rs.eof
listbox1.additem rs.fields("字段名称").value
rs.movenext
loop

回答2:

利用循环加入