个人一岗双责情况汇报:为什么一运行程序就会说from子语句错误啊?

来源:百度文库 编辑:神马品牌网 时间:2024/05/06 17:46:16
程序如下:
Option Explicit
Dim cnt As Integer '记录确定次数

Private Sub Cancel_Click()
conn.Close
Set conn = Nothing
End
End Sub

Private Sub login_Click()
Dim sql As String
Dim rs_login As New ADODB.Recordset
If Trim(txtname.Text) = "" Then '判断输入的用户名是否为空
MsgBox "没有这个用户", vbOKOnly + vbExclamation, ""
txtname.SetFocus
Else
sql = "select * from user where username='" & txtname.Text & "'"
rs_login.Open sql, conn, adOpenKeyset, adLockPessimistic
If rs_login.EOF = True Then
MsgBox "没有这个用户", vbOKOnly + vbExclamation, ""
txtname.SetFocus
Else '检验密码是否正确
If Trim(rs_login.Fields(1)) = Trim(txtpwd.Text) Then
userID = txtname.Text
username = rs_login.Fields(2)
rs_login.Close
Unload Me
interface.Show
Else
MsgBox "密码不正确", vbOKOnly + vbExclamation, ""
txtpwd.SetFocus
End If
End If
End If
cnt = cnt + 1
If cnt = 3 Then
Unload Me
End If
End Sub

Private Sub form_load()
Dim connectionstring As String
connectionstring = "provider=Microsoft.Jet.oledb.4.0;" & _
"data source= " & App.Path & "\fire.mdb"
conn.Open connectionstring
cnt = 0
End Sub

user是SQL的关键字,所以你将数据库表名设置成关键字同名的而在此引用是不被许可的.你可以通过分隔标识符来引用这个对象.所以你这里应该用sql = "select * from [user] where username='" & txtname.Text & "'" 来代替原来的写法.