怎么将数据库表中的数据显示在VB的listbox列表中
2个回答
展开全部
引用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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询