Private Sub Comenter_Click() If Txtname.Text = "" Then MsgBox "用户名不能为空!", vbOKOnly + vbInformation, "友情提示" Txtname.SetFocus Exit Sub End If If Txtpwd.Text = "" Then MsgBox "密码不能为空!", vbOKCancel + vbInformation, "友情提示" Txtpwd.SetFocus Exit Sub End If
Dim strSQL As String strSQL = "select * from Users where [user]='" & Trim$(Txtname.Text) & "' and [password]='" & Trim$(Txtpwd.Text) & "' "
Dim str As New ADODB.Recordset Dim mydb As DataBases Set str = New ADODB.Recordset Set mydb = New DataBases str.CursorLocation = adUseClient mydb.OpenConn str.Open strSQL, mydb.SqlConn, adOpenStatic, adLockReadOnly
With str If .State = adStateOpen Then .Close .Open strSQL If .EOF Then Try_times = Try_times + 1 If Try_times >= 3 Then MsgBox "您已经三次尝试进入本系统,均不成功,系统将自动关闭", vbOKOnly + vbCritical, "警告" Unload Me Else MsgBox "对不起,用户名不存在或密码错误 !", vbOKOnly + vbQuestion, "警告" Txtname.Text = "" Txtpwd.Text = "" End If Else
i = "select type from users where [user]='" & Trim$(Txtname.Text) & "' and [password]='" & Trim$(Txtpwd.Text) & "'" j = "select type from users where [user]='" & Trim$(Txtname.Text) & "' and [password]='" & Trim$(Txtpwd.Text) & "'"
If i = 1 Then frmMain.Show '登录进入的另一个界面 Else frmMingXi.Show End If 'Unload Me
i = "select type from users where [user]='" & Trim$(Txtname.Text) & "' and [password]='" & Trim$(Txtpwd.Text) & "'" 这里应该改掉。 Dim rs As New ADODB.Recordset rs.Open "select type from users where [user]='" & Trim$(Txtname.Text) & "' and [password]='" & Trim$(Txtpwd.Text) & "'" , mydb.SqlConn, adOpenStatic, adLockReadOnly if rs.filed("type") <>'' then
上面已经有了 strSQL = "select * from Users where [user]='" & Trim$(Txtname.Text) & "' and [password]='" & Trim$(Txtpwd.Text) & "' " 打开记录,如果结果不为空,这时候TYPE字段已经有了,没必要再运行一个SQL. 红色部分改成: If str.filed("type") = 1 Then frmMain.Show '登录进入的另一个界面 Else frmMingXi.Show End If 'Unload Me