VB中,动态给COMBOBOX添加内容,内容是一个表的字段,方法知道了,但一个窗体中有2个COMBOBOX时,2个数据表取数据,第二个没反应,请指点
如题,程序如下:
Private Sub Form_Load()
Dim sql1, sql2, sqlstr As String
Dim i As Integer
'Dim rst2 As New ADODB.Recordset
'rst rst1全局变量
Set rst = New ADODB.Recordset
Set rst1 = New ADODB.Recordset
'Set rst2 = New ADODB.Recordset
sql1 = "select * from bookclassinfo "
sql2 = "select * from bookpublish "
'connect_db 链接数据库的
Call connect_db
rst1.Open sql2, con, adOpenDynamic, adLockOptimistic
Combo1.Clear
rst1.MoveLast
rst1.MoveFirst
For i = 1 To rst1.RecordCount
Combo1.AddItem rst1.Fields( "出版社名称 ")
rst1.MoveNext
If rst1.EOF Then Exit Sub
Next
Combo1.Text = " "
rst.Open sql1, con, adOpenDynamic, adLockOptimistic
Combo2.Clear
rst.MoveLast
rst.MoveFirst
For i = 1 To rst.RecordCount
Combo2.AddItem rst.Fields( "图书分类 ")
rst.MoveNext
If rst.EOF Then Exit Sub
Next
Combo2.Text = " "
end sub
实验给RST重新建立一个数据库链接也不行,有哪位老兄有好方法吗,急,谢谢,分少,只能少给点了!
还有个问题就是VB中的小FORM能不能实现向播放器有个功能:总是在前的功能。
设计的窗体运行时,如果鼠标点到窗体外面,窗体会消失隐藏,有没有简单的方法让他保持在最前面,除非点击关闭或者退出按钮。
[解决办法]
Private Sub Form_Load()
Dim sql1, sql2, sqlstr As String
Dim i As Integer
'Dim rst2 As New ADODB.Recordset
'rst rst1全局变量
Set rst = New ADODB.Recordset
Set rst1 = New ADODB.Recordset
'Set rst2 = New ADODB.Recordset
sql1 = "select * from bookclassinfo "
sql2 = "select * from bookpublish "
'connect_db 链接数据库的
Call connect_db
rst1.Open sql2, con, adOpenDynamic, adLockOptimistic
Combo1.Clear
rst1.MoveLast
rst1.MoveFirst
For i = 1 To rst1.RecordCount
Combo1.AddItem rst1.Fields( "出版社名称 ")
rst1.MoveNext
If rst1.EOF Then Exit Sub ‘你这里出了函数,还怎么运行下面的阿
Next
Combo1.Text = " "
rst.Open sql1, con, adOpenDynamic, adLockOptimistic
Combo2.Clear
rst.MoveLast
rst.MoveFirst
For i = 1 To rst.RecordCount
Combo2.AddItem rst.Fields( "图书分类 ")
rst.MoveNext
If rst.EOF Then Exit Sub
Next
Combo2.Text = " "
end sub
你设个断点,跟进一下就好了