VB实时错误3709
PrivateSubCommand1_Click(IndexAsInteger)DimsqlAsStringDimconnAsNewADODB.ConnectionDim...
Private Sub Command1_Click(Index As Integer)
Dim sql As String
Dim conn As New ADODB.Connection
Dim rs_login As New ADODB.Recordset
If Trim(Text1.Text) = "" Then
MsgBox "用户名不能为空,请重新输入!", vbOKOnly + vbExclamation, "错误"
Text1.SetFocus
Else
sql = "select * from Test where login = '" & Text1.Text & "'"
rs_login.Open sql, conn, adOpenKeyset, adLockPessimistic
If rs_login.EOF = True Then
MsgBox "用户名不存在,请重新输入!", vbOKOnly + vbExclamation, "错误"
Text1 = ""
Text1.SetFocus
Else
If Trim(rs_login.Fields(1)) = Trim(Text2) Then
rs_login.Close
Unload Me
Form2.Show
Else
MsgBox "密码错误,请重新输入!", vbOKOnly + vbExclamation, "错误"
Text2.SetFocus
End If
End If
End If
End Sub 展开
Dim sql As String
Dim conn As New ADODB.Connection
Dim rs_login As New ADODB.Recordset
If Trim(Text1.Text) = "" Then
MsgBox "用户名不能为空,请重新输入!", vbOKOnly + vbExclamation, "错误"
Text1.SetFocus
Else
sql = "select * from Test where login = '" & Text1.Text & "'"
rs_login.Open sql, conn, adOpenKeyset, adLockPessimistic
If rs_login.EOF = True Then
MsgBox "用户名不存在,请重新输入!", vbOKOnly + vbExclamation, "错误"
Text1 = ""
Text1.SetFocus
Else
If Trim(rs_login.Fields(1)) = Trim(Text2) Then
rs_login.Close
Unload Me
Form2.Show
Else
MsgBox "密码错误,请重新输入!", vbOKOnly + vbExclamation, "错误"
Text2.SetFocus
End If
End If
End If
End Sub 展开
展开全部
解决3709错误原因是,你没有先写连接数据库代码,rs_login是摸不着北的,所以产生3709
conn.open "连接字串..."
待留意的代码问题:
Command1_Click(Index As Integer)是数组控件,每个Index的Command1控件都运行相同的过程?
rs_login.Open sql, conn, adOpenKeyset, adLockPessimistic
建议adOpenKeyset改为adOpenDynamic或adOpenStatic,支持的运行指令比较丰富。If rs_login.EOF = True Then 这句并不代表真正没有数据。
If (rs_login.EOF = True) AND (rs_login.BOF = True) Then才能确定没数据,
倒不如写 if rs_login.recordcount = 0 then 的判断方法
Form2.show 最好写在 Unload Me之前。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询