vb编程,将数据库中的数据导入到combobox中
PrivateSubForm_Load()DimmrcAsADODB.RecordsetDimtxtSQLAsStringDimMsgTextAsStringDimiAs...
Private Sub Form_Load()
Dim mrc As ADODB.Recordset
Dim txtSQL As String
Dim MsgText As String
Dim i As Integer
comboSex.AddItem "男"
comboSex.AddItem "女"
txtSQL = "select * from class_info"
Set mrc = ExecuteSQL(txtSQL, MsgText)
'添加内容到列表框中
For i = 1 To mrc.Record.Count
comboClassNo.AddItem mrc.Fields(0)
mrc.MoveNext
Next i
mrc.Close
End Sub 展开
Dim mrc As ADODB.Recordset
Dim txtSQL As String
Dim MsgText As String
Dim i As Integer
comboSex.AddItem "男"
comboSex.AddItem "女"
txtSQL = "select * from class_info"
Set mrc = ExecuteSQL(txtSQL, MsgText)
'添加内容到列表框中
For i = 1 To mrc.Record.Count
comboClassNo.AddItem mrc.Fields(0)
mrc.MoveNext
Next i
mrc.Close
End Sub 展开
4个回答
展开全部
帮你改了!注意Dim mrc As New ADODB.Recordset 少了New。
只要将mrc.Close删除就可以了。然后在TxtSQL上面加上If mrc.State = adStateOpen Then mrc.Close具体代码请看下
Dim mrc As New ADODB.Recordset
Dim txtSQL As String
Dim MsgText As String
Dim i As Integer
comboSex.AddItem "男"
comboSex.AddItem "女"
If mrc.State = adStateOpen Then mrc.Close
txtSQL = "select * from class_info"
Set mrc = ExecuteSQL(txtSQL, MsgText)
'添加内容到列表框中
comboClassNo.Clear
mrc.MoveFirst
Do While Not mrc.EOF
comboClassNo.AddItem mrc.Fields(0).value
mrc.MoveNext
Loop
End Sub
只要将mrc.Close删除就可以了。然后在TxtSQL上面加上If mrc.State = adStateOpen Then mrc.Close具体代码请看下
Dim mrc As New ADODB.Recordset
Dim txtSQL As String
Dim MsgText As String
Dim i As Integer
comboSex.AddItem "男"
comboSex.AddItem "女"
If mrc.State = adStateOpen Then mrc.Close
txtSQL = "select * from class_info"
Set mrc = ExecuteSQL(txtSQL, MsgText)
'添加内容到列表框中
comboClassNo.Clear
mrc.MoveFirst
Do While Not mrc.EOF
comboClassNo.AddItem mrc.Fields(0).value
mrc.MoveNext
Loop
End Sub
展开全部
comboClassNo.AddItem mrc.Fields(0)
改成
comboClassNo.AddItem mrc.Fields(i)
改成
comboClassNo.AddItem mrc.Fields(i)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
直接用datacombo控件
rowsource绑定
rowsource绑定
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
什么意思?出错了吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询