OLEDB访问报告"语法错误"但声明看起来是正确的 [英] Access OLEDB reports "syntax error" but the statement looks correct

查看:177
本文介绍了OLEDB访问报告"语法错误"但声明看起来是正确的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.net编写一个简单的页面更新的Access表的密码。下面是一个可行的SELECT查询语法:

I'm writing a simple page in ASP.net to update a password in a Access table. Here's syntax for a SELECT query that works:

    Dim dbConn As OleDbConnection
    Dim dbCommand As OleDbCommand
    Dim dbReader As OleDbDataReader

    'Connect to db
    dbConn = New OleDbConnection(Application("strConnectionString"))
    dbConn.Open()

    'Get user info
    strSQL = "SELECT * FROM users WHERE Username = '" & strUsername & "';"
    dbCommand = New OleDbCommand(strSQL, dbConn)
    dbReader = dbCommand.ExecuteReader()

和我的连接字符串:

    Application("strConnectionString") = _
        "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strDBPath & _
            "; Jet OLEDB:Database Password=" & strDBPassword & ";"

中的SELECT工作得很好,所以我知道我的连接正常。但是,这个查询给了我一个语法错误:

The SELECT works fine, so I know my connection is OK. But this query gives me a syntax error:

strSQL = "UPDATE users SET Password = '1'"

通过一切一样,ASP错误说,有我的语法错误。但是,当我RESPONSE.WRITE的STRSQL线,它给了我这样的:

With everything else the same, the ASP error says there is an error with my syntax. But when I response.write the strSQL line, it gives me this:

UPDATE users SET Password = '1' 

当我粘贴到一个访问查询编辑器此,查询更新表中的'1'所有'密码'字段,所以我知道语法确定。我试了一下没有DataReader的使用dbCommand.ExecuteNonQuery(),同样的结果。

and when I paste this into a query editor in Access, the query updates all 'Password' field in the table to '1', so I know the syntax is OK. I tried it without the datareader and using dbCommand.ExecuteNonQuery(), same result.

我已经有了设置,以便每个人都有完全控制访问文件的权限,所以我不认为这是一个权限问题。

I've got the permissions on the Access file set so that everybody has full control, so I don't think it's a permission problem.

任何人能看到我的错误?我真的很坚持。谢谢你。

Can anybody see my mistake? I'm really stuck. Thanks.

推荐答案

密码是的在访问SQL保留字所以你需要它括在方括号,如果它是一个列名。

PASSWORD is a reserved word in Access SQL so you need to enclose it in square brackets if it is a column name.

strSQL = "UPDATE users SET [Password] = '1'" 

这篇关于OLEDB访问报告"语法错误"但声明看起来是正确的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆