用VB来实现一个用户登陆

来源:百度知道 编辑:UC知道 时间:2024/06/26 05:37:53
Private Sub cmdOK_Click()
Dim SQL As String
Dim rs As ADODB.Recordset
If Trim(UserName.Text = "") Then
MsgBox "没有输入用户名称,请重新输入!", vbOKOnly + vbExclamation, "警告"
UserName.SetFocus
Else '查询用户
SQL = "select * from UserInfo where UserID='" & UserName.Text & "'"
Set rs = TransactSQL(SQL)
If iflag = 1 Then
If rs.EOF = True Then
MsgBox "没有这个用户,请重新输入!", vbOKOnly + vbExclamation, "警告"
UserName.SetFocus
Else
If Trim(rs.Fields(1)) = Trim(PassWord.Text = "12345") Then
rs.Close
Me.Hide
gUserName = Trim(UserName.Text) '保存用户名称
FrmMain.Show

Option Explicit
Dim intTryTimes As Integer
Dim dbLogin As Database
Dim rstLogin As Recordset

Private Sub cmdLoginCancel_Click()
End
End Sub

Private Sub cmdLoginEnter_Click()
If Me.txtUser = "" Then
MsgBox "用户名不能为空!", vbCritical, Me.Caption
Me.txtUser.SetFocus
GoTo ExitSub
ElseIf Me.txtPwd = "" Then
MsgBox "请填写密码!", vbCritical, Me.Caption
Me.txtPwd.SetFocus
GoTo ExitSub
End If
Set rstLogin = dbLogin.OpenRecordset("select * from User where Username='" + Trim(Me.txtUser) + "'")
If rstLogin.RecordCount = 0 Then
MsgBox "用户名填写错误!", vbCritical, "错误"
Me.txtUser.SetFocus
Me.txtUser.SelStart = 0
Me.txtUser.SelLength = Len(Me.txtUser)
GoTo ExitSub
End If