If textUserName.Text = "" Then Exit Sub
Dim cnt As ADODB.Connection
Set cnt = New ADODB.Connection
cnt.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" & txtUserName & " ;PASSWORD = " & txtPassword & " ;Initial Catalog=" & txtDataBase & ";Data Source=" & txtServer
Dim rs As New ADODB.Recordset
rs.Open "SELECT * FROM UserName where username = '" & textUserName.Text & "'", cnt, adOpenKeyset, adLockOptimistic
If rs.EOF Then
MsgBox "该用户不存在,再试一次!", vbOKOnly Or vbExclamation, "登录"
textUserName.SetFocus
rs.Close
cnt.Close
Else
If StrComp(textPassword.Text, rs!Password) = 0 Then
constant.TureName = rs!TureName
Unload Me
frmMain.Show
rs.Close
cnt.Close
Else
MsgBox "密码错误,再试一次!", vbOKOnly Or vbExclamation, "登录"
textPassword = ""
textPassword.SetFocus
rs.Close
cnt.Close
End If
End If
If txtName.text <> "" Then
str = "select * from USERNAME where UserName='" & txtName & "'"
rs.Open str, con, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
...
Else
rs.close
...
End If
End If
End Sub
If txtName.text <> "" Then
str = "select * from USERNAME where UserName='" & txtName & "'"
rs.Open str, con, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
...
Else
re.close
...
End If
End If
End Sub
Public LoginSucceeded As Boolean
Dim mConn As New ADODB.Connection
Dim mRst As New ADODB.Recordset
Dim strDBName As String
Private Sub cmdCancel_Click()
LoginSucceeded = False
Me.Hide
End Sub
Private Sub cmdOK_Click()
Dim sUserName As String
Dim strSQL As String
mConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBName & ";Persist Security Info=False"
mConn.Open
sUserName = Trim(txtUserName.Text)
strSQL = "Select * from User where UserID='" & sUserName & "'"
mRst.Open strSQL, mConn, adOpenDynamic, adLockOptimistic
If mRst.EOF Then
MsgBox "没有该用户!", vbCritical
Exit Sub
Else
If txtPassword = mRst.Fields("password") Then
LoginSucceeded = True
Me.Hide
Else
MsgBox "密码错误,请重试!", vbCritical, "登陆"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
End If
End Sub
Private Sub Form_Load()
strDBName = "C:\Test.mdb"
End Sub