Public LoginSucceeded As Boolean
Dim Conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub cmdCancel_Click()
End
End Sub
Private Sub cmdOK_Click()
Dim strUserName$, strPassword$, strSQL$
Static Count As Byte '数据规格化
strUserName = Replace(Trim(txtUserName.Text), "", "")
strPassword = Replace(Trim(txtPassword.Text), "", "")
If strUserName = "" Then
MsgBox "用户名不能为空,请输入用户名!"
txtUserName.SetFocus
Exit Sub
ElseIf strPassword = "" Then
MsgBox "密码不能为空,请输入密码!"
txtPassword.SetFocus
Exit Sub
End If '查询数据库中是否存在满足条件的用户名
Connstring = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=f:\vb\db1.mdb;Persist Security Info=False"
With Conn
.ConnectionString = Connstring
.CommandTimeout = 10
.Open
End With
MsgBox "连接成功"
strSQL = "SELECT * FROM pwd WHERE UserName='" & strUserName & "' "
strSQL = strSQL & "AND Password= '" & strPassword & "';"
'rs.Open strSQL, Conn
'If rs.EOF Then
Count = Count + 1
MsgBox "用户名不存在或密码错误!"
txtUserName.Text = ""
txtPassword.Text = ""
txtUserName.SetFocus
'Else
UserName = Trim(txtUserName.Text)
MDIForm1.Show
Me.Hide
'End If
'rs.Close
Conn.Close
Set rs = Nothing
Set Conn = Nothing
If Count >= 3 Then
MsgBox "超过登录次数,无权登录本系统!", , "登录失败"
End '退出系统
End If
End Sub
Private Sub Form_Load()
LoginSucceeded = False
End Sub
这是个登陆窗口的代码~~要连接ACCESS的数据库,请问下有哪里不妥~~老运行不成功~~不知哪里有问题~~
帮我看下吧~~