Private Sub cmd_ok_Click()
Dim namekey As String
Dim passwordkey As String
Dim try_times As Integer If Trim(txtuser.Text) = "" Then
MsgBox "请输入用户名", vbOKOnly
txtuser.SetFocus
Exit Sub
End If
If Trim(txtpwd.Text) = "" Then
MsgBox "请输入密码", vbOKOnly
txtpwd.SetFocus
Exit Sub
End If
namekey = Trim(txtuser)
passwordkey = Trim(txtpwd)
Dim strsql As String Dim odbcstr As String, objconn As New ADODB.Connection, objrs As New ADODB.Recordset
odbcstr = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=sa;Initial Catalog=;Data Source="
objconn.Open odbcstr
strsql = "select * from tb_operator where name='" + namekey + "'"
objrs.Open strsql, objconn, adOpenDynamic, adLockOptimistic
If objrs.EOF = True Then
MsgBox "没有该用户!", vbOKOnly
txtuser = ""
txtpwd = ""
try_times = try_times + 1
If try_times >= 3 Then
MsgBox "您已经三次尝试进入本系统,均不成功,系统将关闭"
Unload Me
Else
Exit Sub
End If
objrs.Close
Exit SubEnd If
If passwordkeyobjrs.Fields(2) Then
MsgBox "密码不正确!"
txtpwd = ""
try_times = try_times + 1
If try_times >= 3 Then
MsgBox "您已经三次尝试进入本系统,均不成功,系统将关闭"
Unload Me
Else
Exit Sub
End If
objrs.Close
Exit Sub Else
If objrs.Fields(3) = 1 Then
frm_mainuser.Show
Unload Me
Else
MsgBox "用户类型不正确!请以普通用户方式登录!"
txtuser = ""
txtpwd = ""
End If
objrs.Close
Exit SubEnd IfEnd Sub这是连接SQL数据库的,不知你要的是不是这个,我已经做过了,可以运行的,你COPE后,改一下服务器及数据库的名称即可. |