vb做的登录界面 与access连接
数据库用access 数据库名是user 表名是user 字段是username,password
代码如下:但是有错误,请高手们帮帮忙指出,谢谢
Option Explicit
Dim cnt As Integer '记录确定次数
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
Dim strAccess As String
Dim rs As New ADODB.Recordset
Dim conn As New ADODB.Connection
Dim sql As String
Dim connstr As String
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False; data source=" & "user.mdb "
If Trim(text1.Text) = "" Then
MsgBox "用户名不能为空,请重新输入!"
text1.SetFocus
Else
sql = "select * from user where username='" & Trim(text1.Text) & "'"
rs.Open "user", conn, adOpenKeyset, adLockPessimistic '打开记录集
If rs.EOF = True Then
MsgBox "没有这个用户,请重输入!", vbOKOnly + vbExclamation, ""
text1.Text = ""
text1.SetFocus
Else
If Trim(rs.Fields(1)) = Trim(text2.Text) Then
Unload Me
frmLogin.Show
Else
MsgBox "密码不正确,请重输入!", vbOKOnly + vbExclamation, ""
text2.SetFocus
text2.Text = ""
End If
End If
End If
cnt = cnt + 1
If cnt = 3 Then
Unload Me
End If
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Call cmdOK_Click
End If
End Sub
Private Sub Form_Load()
cnt = 0
End Sub
[解决办法]
sql语句没用到啊,应该是这样:
rs.Open sql, conn, adOpenKeyset, adLockPessimistic '打开记录集
试试。。。
[解决办法]
select * from user where
改成:
select * from [user] where
user是系统关键字,不建议作为表名与字段名来使用,一定要用则需要用方括号括起来
[解决办法]
直接用 Find 就好了 还那么麻烦干啥 ?
Rs.MoveFirst
Rs.Find "usernm = " & Chr(39) & Text1.Text & Chr(39)
If Not Rs.EOF Then FindUser = True