Access OLEDB 报告“语法错误";但声明看起来是正确的

2

本文介绍了Access 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' 

当我将其粘贴到 Access 中的查询编辑器中时,查询会将表中的所有密码"字段更新为1",所以我知道语法是可以的.我在没有数据读取器并使用 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.

我已经获得了 Access 文件集的权限,因此每个人都可以完全控制,所以我认为这不是权限问题.

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.

推荐答案

PASSWORD 是 Access 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'" 

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

The End

相关推荐

我可以使用 lambda 语法忽略委托参数吗?
Can I ignore delegate parameters with lambda syntax?(我可以使用 lambda 语法忽略委托参数吗?)...
2023-11-11 C#/.NET开发问题
7

在 C# 中附加事件处理程序的 2 种不同方式是否存在实际差异?
Is there an actual difference in the 2 different ways of attaching event handlers in C#?(在 C# 中附加事件处理程序的 2 种不同方式是否存在实际差异?)...
2023-11-11 C#/.NET开发问题
5

有和没有“新"的接线事件之间的区别
Difference between wiring events with and without quot;newquot;(有和没有“新的接线事件之间的区别)...
2023-11-11 C#/.NET开发问题
2

Func<string,string> 有什么区别?和委托?
What is the difference between Funclt;string,stringgt; and delegate?(Funclt;string,stringgt; 有什么区别?和委托?)...
2023-11-11 C#/.NET开发问题
3

代表的@前缀有什么特殊含义吗?
Does the @ prefix for delegates have any special meaning?(代表的@前缀有什么特殊含义吗?)...
2023-11-11 C#/.NET开发问题
3

C#中的委托语法问题
Problem with delegate Syntax in C#(C#中的委托语法问题)...
2023-11-10 C#/.NET开发问题
2