vb与access联接的登录界面无法进入!!!!

来源:百度知道 编辑:UC知道 时间:2024/05/31 03:13:09
以下是登录按钮的代码:
Private Sub Command1_Click()
If Text1.Text = "" Then
MsgBox "请填写用户名!", vbInformation + vbOKOnly, "警告"
Text1.SetFocus
Exit Sub
End If

If Text2.Text = "" Then
MsgBox "请填写密码!", vbInformation + vbOKOnly, "警告"
Text2.SetFocus
Exit Sub
End If
g_strsql = "select * from readerinfo where 姓名='" & Text1.Text & "' and 密码='" & Text2.Text & "'"
Set g_rs = g_db.OpenRecordset(g_strsql)
If Text1.Text = g_rs!姓名 And Text2.Text = g_rs!密码 Then

Me.Hide
Form4.Show

Else
MsgBox "对不起,你输入的用户和密码不正确,请重新输入!", vbInformation + vbOKOnly, "警告"
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End If
Set g_rs = Nothing

End Sub
以下是我添加的模块的代码:

我认为是这代码有问题
If Text1.Text = g_rs!姓名 And Text2.Text = g_rs!密码 Then
其实你执行了SQL语句,就已经判断了用户密码是否存在,这个判断语句反而是错误的,应该换成 if g_rs.eof=false then

你这是用DAO访问数据库的,有点费事,还不如用ADO访问。以下是我按照你的要求写的登陆代码,与其它代码完全独立,你只要在登陆界面里换成这些代码就能访问成功
public cnn as ADODB.connection
public rs as ADODB.recordset
'以上代码放在通用中

private sub form_load()
Text2.PasswordChar = "*"
set cnn = new ADODB.connection
set rs = new ADODB.recordset
cnn.open "Provider=Microsoft.Jet.OLEDB.4.0;database passwordData Source=" & App.Path & "\weldES.mdb" & ";Persist Security Info=True" '打开数据库
end sub

Private Sub Command1_Click()
If Text1.Text = "" Then
MsgBox "请填写用户名!", vbInformation + vbOKOnly, "警告"
Text1.SetFocus
Exit Sub
End If

If Text2.Text = "" Then
MsgBox "请填写密码!", vbInformation + vbOKOnly, &quo