VB中怎么把ACCESS中某个表的一列数值,加到combobox的下拉列表中?初学VB,请大家多帮帮忙,
1个回答
展开全部
菜单“工程”-“引用”,找到以下库打勾:
Microsoft ActiveX Data Objects 2.x Library
Microsoft ActiveX Data Objects Recordset 2.x Library
代码:
Dim cnn as ADODB.Connection
Dim rs as ADODC.Recordset
Cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="ACCESS文件.mdb;Persist Security Info=False"
cnn.Open
rs.Open "select field1 from table1", cnn, adOpenForwardOnly, adLockReadOnly.adCmdText
combo1.Clear
Do While Not rs.EOF
combo1.AddItem rs.Fields(0) & ""
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
cnn.Close
Set cnn = Nothing
Microsoft ActiveX Data Objects 2.x Library
Microsoft ActiveX Data Objects Recordset 2.x Library
代码:
Dim cnn as ADODB.Connection
Dim rs as ADODC.Recordset
Cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="ACCESS文件.mdb;Persist Security Info=False"
cnn.Open
rs.Open "select field1 from table1", cnn, adOpenForwardOnly, adLockReadOnly.adCmdText
combo1.Clear
Do While Not rs.EOF
combo1.AddItem rs.Fields(0) & ""
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
cnn.Close
Set cnn = Nothing
更多追问追答
追问
您好感谢你的回答,但是似乎不需要那么麻烦,应该有用到data控件,怎么把data控件里的数据取出来赋值给combobox或者textbox,不是设置datafield
追答
你是要设置一张列表而不是单个值,没法用简单的绑定的方式显示数据的。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询