帮我看看这是为什么????

qd_zhang_ning 2003-11-21 05:50:56
在VB中使用ADO与Access数据库 建立登录对话窗体:
Access中建立数据库:testdb.mdb 表 user 属性 user_account,user_password
vb工程中代码如下:
Option Explicit
Dim result As Integer

Private Sub Command1_Click()
If Text1.Text = "" Or Text2.Text = "" Then
MsgBox "用户名/密码不能为空"
Exit Sub
End If

result = UserValidate(Text1.Text, Text2.Text)

If result = 0 Then

Unload Me
Else
Select Case result
Case 1:
MsgBox "用户" & frmLogin.Text1 & "不存在"
Case 2:
MsgBox "用户" & frmLogin.Text1 & "密码错误"
Case Else
MsgBox "为知错误"
End Select
End If
End Sub

Private Sub Command2_Click()

End

End Sub

Function UserValidate(input_user As String, input_password As String) As Integer
Dim rs As New ADODB.Recordset
Dim sql As String
Dim tmp_password As String
Dim conn As New ADODB.Connection

conn.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source= " & App.Path & "\testdb.mdb;persist security info=false"
conn.Open
rs.ActiveConnection = conn
sql = "select user_account,user_password FROM user where user_account ='" & input_user & "'"
Call rs.Open(sql, conn)

If (rs.EOF) Then
UserValidate = 1
rs.Close
conn.Close
Exit Function
End If

tmp_password = rs("user_password")

rs.Close
conn.Close

If StrComp(tmp_password, input_password) Then
UserValidate = 2
Exit Function
End If

UserValidate = 0

End Function

Private Sub Form_Load()
result = -1

End Sub
Private Sub form_unload(cancel As Integer)
If (Not result) Then
frmMain.Show
End If
End Sub

每次按F5调试,输入正确的用户名和密码总是返回错误信息:“Form 子句语法错误” 但我看不出哪错,到底错在哪呢?
...全文
20 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yoki 2003-11-21
  • 打赏
  • 举报
回复
user为access数据库的保留字,必须用[]括起来
饮水需思源 2003-11-21
  • 打赏
  • 举报
回复
sql = "select user_account,user_password FROM [user] where user_account ='" & input_user & "'"
'尽量少用系统关键字(user为系统关键字)

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧