我要模拟抽奖系统,两个按钮一个Label或TextBox,点击开始按钮,就是让数据库中的号码不停地在窗体上多行滚动,点击停止按钮,就停下来。但不能重复抽!!!
在下是个菜鸟只能想到如下:
Dim CN As ADODB.Connection
Dim StartLoop As Boolean
Dim SqlStr As String
Private Sub Form_load()
CN.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\...\db1.mdb;Persist Security Info=False"
CN.Open
End Sub
Private Sub CommandButton1_Click()
Dim starTime As Single
Dim rs As ADODB.Recordset
StartLoop = True
SqlStr = "select call_no from pd_users where 1=1"
Set rs = CN.Execute(SqlStr)
rs.MoveFirst
Do While StartLoop
starTime = Timer
Do While Timer - starTime < 0.1
DoEvents
If StartLoop = False Then Exit Do
Loop
TextBox1 = rs("call_no")
rs.MoveNext
On Error Resume Next
If rs.EOF Then
rs.MoveFirst
Else
rs.MoveNext
End If
Loop
rs.Close
End Sub
Private Sub CommandButton2_Click()
StartLoop = False
End Sub
系统提示说:对象变量或With块变量未设置,并指向这句“Set rs = CN.Execute(SqlStr)”请大家帮忙看看;
还有,我在SQL语句查询后在多一步操作,将查询处的call_no的state字段的值改为1
应该怎么改!!谢谢大家!!
在下是个菜鸟只能想到如下:
Dim CN As ADODB.Connection
Dim StartLoop As Boolean
Dim SqlStr As String
Private Sub Form_load()
CN.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\...\db1.mdb;Persist Security Info=False"
CN.Open
End Sub
Private Sub CommandButton1_Click()
Dim starTime As Single
Dim rs As ADODB.Recordset
StartLoop = True
SqlStr = "select call_no from pd_users where 1=1"
Set rs = CN.Execute(SqlStr)
rs.MoveFirst
Do While StartLoop
starTime = Timer
Do While Timer - starTime < 0.1
DoEvents
If StartLoop = False Then Exit Do
Loop
TextBox1 = rs("call_no")
rs.MoveNext
On Error Resume Next
If rs.EOF Then
rs.MoveFirst
Else
rs.MoveNext
End If
Loop
rs.Close
End Sub
Private Sub CommandButton2_Click()
StartLoop = False
End Sub
系统提示说:对象变量或With块变量未设置,并指向这句“Set rs = CN.Execute(SqlStr)”请大家帮忙看看;
还有,我在SQL语句查询后在多一步操作,将查询处的call_no的state字段的值改为1
应该怎么改!!谢谢大家!!
set CN=new adodb.connection
SqlStr = "update pd_users set call_no=call_no+1 where 1=1"
Set rs = CN.Execute(SqlStr)
Dim CN As ADODB.Connection
Dim StartLoop As Boolean
Dim SqlStr As String
Private Sub Form_load()
Set CN = New ADODB.Connection
CN.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\...\db1.mdb;Persist Security Info=False"
CN.Open
End Sub
Private Sub CommandButton1_Click()
Dim starTime As Single
Dim rs As ADODB.Recordset
StartLoop = True
SqlStr = "select call_no from pd_users where 1=1"
Set rs = CN.Execute(SqlStr)
rs.MoveFirst
Do While StartLoop
starTime = Timer
Do While Timer - starTime < 0.1
DoEvents
If StartLoop = False Then Exit Do
Loop
TextBox1 = rs("call_no")
rs.MoveNext
On Error Resume Next
If rs.EOF Then
rs.MoveFirst
Else
rs.MoveNext
End If
Loop
rs.Close
End Sub
Private Sub CommandButton2_Click()
StartLoop = False
End Sub
系统仍提示说:对象变量或With块变量未设置,并指向这句“Set rs = CN.Execute(SqlStr)”
还有,由于小弟是个菜鸟,可能理解的不对,你的意思是说将SqlStr = "select call_no from pd_users where 1=1"替换为SqlStr = "update pd_users set call_no=call_no+1 where 1=1"么??
set rs=new adodb.recordset
Dim CN As New ADODB.Connection
Din rs As New ADODB.Recordset
Dim CN As New ADODB.Connection
Dim StartLoop As Boolean
Dim SqlStr As String
Private Sub Form_load()
Set CN = New ADODB.Connection
CN.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\...\db1.mdb;Persist Security Info=False"
CN.Open
End Sub
Private Sub CommandButton1_Click()
Dim starTime As Single
Dim rs As New ADODB.Recordset
StartLoop = True
SqlStr = "select call_no from pd_users where 1=1"
Set rs = CN.Execute(SqlStr)
rs.MoveFirst
Do While StartLoop
starTime = Timer
Do While Timer - starTime < 0.1
DoEvents
If StartLoop = False Then Exit Do
Loop
TextBox1 = rs("call_no")
rs.MoveNext
On Error Resume Next
If rs.EOF Then
rs.MoveFirst
Else
rs.MoveNext
End If
Loop
rs.Close
End Sub
Private Sub CommandButton2_Click()
StartLoop = False
End Sub
系统提示说:对象关闭时,操作不被允许。并指向这句“Set rs = CN.Execute(SqlStr)”
改为:
rs.Open SqlStr, CN, adOpenStatic, adLockOptimistic还有:
TextBox1 = rs("call_no")应该改为TextBox1 = rs![call_no]
Dim CN As New ADODB.Connection
Dim StartLoop As Boolean
Dim SqlStr As String
Private Sub Form_load()
Set CN = New ADODB.Connection
CN.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\jbproject\ÐÂÆÀ·Öϵͳ\db1.mdb;Persist Security Info=False"
CN.Open
End Sub
Private Sub CommandButton1_Click()
Dim starTime As Single
Dim rs As New ADODB.Recordset
StartLoop = True
SqlStr = "select id from test where state=0"
SqlStr = "update test set state=1 where id=" & TextBox1.Text
Set rs = CN.Execute(SqlStr)
rs.MoveFirst
Do While StartLoop
starTime = Timer
Do While Timer - starTime < 0.1
DoEvents
If StartLoop = False Then Exit Do
Loop
TextBox1 = rs![call_no]
rs.MoveNext
On Error Resume Next
If rs.EOF Then
rs.MoveFirst
Else
rs.MoveNext
End If
Loop
rs.Close
End Sub
Private Sub CommandButton2_Click()
StartLoop = False
End Sub系统提示说:对象关闭时,操作不被允许。并指向这句“Set rs = CN.Execute(SqlStr)”
数据库是access,只有一个表test,两个字段id、state,id中就是数字,state初始都是0
SQL因该不会有错吧
set cn=new adodb.connection
set rs=new adodb.Recordset
Dim rs As ADODB.Recordset
改為Dim CN As new ADODB.Connection
Dim rs As new ADODB.Recordset
把Dim rs As ADODB.Recordset改为
Dim rs As New ADODB.Recordset
set rs.ActiveConnection = 某个数据库名