求高手相助我把,VB连接Access有问题,自己搞不定啊,挥泪
桌面.rar
(81.73 KB)
高手们,请帮帮忙啊,小女子纠结这个问题很久了,大致是这样子的,我要用VB去连接数据库,是2003版本的,一开始用Data控件不行,我就改用ADO了,后来就发现有个问题,我的Access的内容是 然后当用户名中输入1,密码框中输入1,按回车或者登陆按钮都是可以的,但是如果密码框中输入2,按回车就显示密码错误,但是很奇怪如果按登陆竟然也是对的,同样的当用户名输入2,密码输入2,按登陆可以进入,但是回车却显示错误,纠结,我是一个大菜鸟yonghuming password
1 1
2 2
程序代码:
Option Explicit Dim SqlStr As String Private Sub Command1_Click() Dim Yonghuming As String If Text1.Text <> "" And Text2.Text <> "" Then '检查是否输入了数据 Yonghuming = Text1.Text Adodc1.RecordSource = "Admin" '设置使用的表 SqlStr = "SELECT password FROM Admin WHERE yonghu='" & Yonghuming & "'" '输入SQL语句,查询密码 Adodc1.RecordSource = SqlStr If Adodc1.Recordset.Fields("password") <> Text2 Then '检查密码是否正确 MsgBox "你的用户名或密码有错误!", , "发生错误了!" Text2.Text = "" Exit Sub End If Me.Hide '若密码正确则进入管理界面 guanli.Show Else MsgBox "请输入用户名与密码!", , "发生错误了!" End If End Sub Private Sub Command2_Click() End End Sub Private Sub Form_Activate() Text1.Text = "" Text2.Text = "" Text1.SetFocus End Sub Private Sub Form_Load() Adodc1.RecordSource = App.Path & "\Database11.mdb" End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Text2.SetFocus End Sub Private Sub Text2_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Command1_Click End Sub