帮我看看用户名和密码该输入什么样子的,谢谢,给个例子 5
OptionExplicitPrivatestrSQLAsStringPrivatestrMsgTextAsString'登陆PrivateSubcmdLogin_Cli...
Option Explicit
Private strSQL As String
Private strMsgText As String
'登陆
Private Sub cmdLogin_Click()
'声明ADODB.Recordset对象变量
Dim objRecordset As ADODB.Recordset
'声明SQL字符串
Dim strSQL As String
'查找用户名
strSQL = "select UserName from Users where UserName='" & _
Trim(txtUserName.Text) & "'"
'获得符合输入的用户记录集
Set objRecordset = ExeCuteSQL(strSQL, strMsgText)
'如果输入的用户不存在
If objRecordset.EOF = True Then
MsgBox " 用户名错误!", vbExclamation + vbOKOnly, "警告"
txtUserName.SetFocus
txtUserName.SelStart = 0
txtUserName.SelLength = Len(txtUserName.Text)
Exit Sub
End If
'从数据库中获得用户名
UserName = objRecordset.Fields(0)
'查找用密码
strSQL = "select UserName from Users where Password='" & _
Trim(txtPassword.Text) & "'"
'获得符合输入的密码记录集
Set objRecordset = ExeCuteSQL(strSQL, strMsgText)
'如果输入的密码不存在
If objRecordset.EOF = True Or Trim(UserName) <> Trim(objRecordset.Fields(0)) Then
MsgBox "密码错误!", vbExclamation + vbOKOnly, "警告"
txtPassword.SetFocus
txtPassword.SelStart = 0
txtPassword.SelLength = Len(txtPassword.Text)
Exit Sub
End If
'显示主界面
frmMain.Show
'卸载登陆窗体
Unload Me
End Sub
'退出登陆
Private Sub cmdQuit_Click()
Unload Me
End Sub
Private Sub Form_Load()
'获取数据库的位置
strConnect = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=HumanResouce;Data Source=."
End Sub
'输入用户名
Private Sub txtUserName_KeyPress(KeyAscii As Integer)
'输入回车表示输入结束,密码框获得焦点
If KeyAscii = 13 Then
txtPassword.SetFocus
End If
End Sub
'输入密码
Private Sub txtPassword_KeyPress(KeyAscii As Integer)
'输入回车表示输入结束,登陆按钮获得焦点
If KeyAscii = 13 Then
cmdLogin.SetFocus
End If
End Sub 展开
Private strSQL As String
Private strMsgText As String
'登陆
Private Sub cmdLogin_Click()
'声明ADODB.Recordset对象变量
Dim objRecordset As ADODB.Recordset
'声明SQL字符串
Dim strSQL As String
'查找用户名
strSQL = "select UserName from Users where UserName='" & _
Trim(txtUserName.Text) & "'"
'获得符合输入的用户记录集
Set objRecordset = ExeCuteSQL(strSQL, strMsgText)
'如果输入的用户不存在
If objRecordset.EOF = True Then
MsgBox " 用户名错误!", vbExclamation + vbOKOnly, "警告"
txtUserName.SetFocus
txtUserName.SelStart = 0
txtUserName.SelLength = Len(txtUserName.Text)
Exit Sub
End If
'从数据库中获得用户名
UserName = objRecordset.Fields(0)
'查找用密码
strSQL = "select UserName from Users where Password='" & _
Trim(txtPassword.Text) & "'"
'获得符合输入的密码记录集
Set objRecordset = ExeCuteSQL(strSQL, strMsgText)
'如果输入的密码不存在
If objRecordset.EOF = True Or Trim(UserName) <> Trim(objRecordset.Fields(0)) Then
MsgBox "密码错误!", vbExclamation + vbOKOnly, "警告"
txtPassword.SetFocus
txtPassword.SelStart = 0
txtPassword.SelLength = Len(txtPassword.Text)
Exit Sub
End If
'显示主界面
frmMain.Show
'卸载登陆窗体
Unload Me
End Sub
'退出登陆
Private Sub cmdQuit_Click()
Unload Me
End Sub
Private Sub Form_Load()
'获取数据库的位置
strConnect = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=HumanResouce;Data Source=."
End Sub
'输入用户名
Private Sub txtUserName_KeyPress(KeyAscii As Integer)
'输入回车表示输入结束,密码框获得焦点
If KeyAscii = 13 Then
txtPassword.SetFocus
End If
End Sub
'输入密码
Private Sub txtPassword_KeyPress(KeyAscii As Integer)
'输入回车表示输入结束,登陆按钮获得焦点
If KeyAscii = 13 Then
cmdLogin.SetFocus
End If
End Sub 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询