SQL Server CE Where 子句问题
我有一个简单的 SQL Server CE 数据库,试图更新表中的一行。以下命令有效:
UPDATE ConsoleUsage
SET TotalCircuits = 123
但是上面的命令更新所有行,所以我想要的是:
UPDATE ConsoleUsage
SET TotalCircuits = 123
WHERE Index = 912
目的是更新表中的单行。但此命令失败,给出以下神秘错误消息(此处使用 MS 建议的格式):
错误代码:80040E37
消息:[ UPDATE ConsoleUsage SET TotalCircuits = 123 WHERE Index = 912 ]
小错误:0
来源:SQL Server 2005 移动版 ADO.NET 数据提供程序
犯错。帕。 :更新 ConsoleUsage SET TotalCircuits = 123 WHERE Index = 912
“Index”列是表的索引,我已经检查了所有拼写,并且在使用和不使用 cmd.CommandType = CommandType.TableDirect; 的情况下都尝试过此操作;和 cmd.IndexName = "MainIndex";
我缺少什么?
I have a simple SQL Server CE database, trying to update a row in a table. The following command works:
UPDATE ConsoleUsage
SET TotalCircuits = 123
But the above command updates all rows, so what I want is this:
UPDATE ConsoleUsage
SET TotalCircuits = 123
WHERE Index = 912
The intent is to update a single row in the table. But this command fails, giving the following cryptic error message (here using MS suggested format):
Error Code: 80040E37
Message : [ UPDATE ConsoleUsage SET TotalCircuits = 123 WHERE Index = 912 ]
Minor Err.: 0
Source : SQL Server 2005 Mobile Edition ADO.NET Data Provider
Err. Par. : UPDATE ConsoleUsage SET TotalCircuits = 123 WHERE Index = 912
The "Index" column is an index to the table, I've checked all spelling and I've tried this both with and without cmd.CommandType = CommandType.TableDirect; and cmd.IndexName = "MainIndex";
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为“索引”是一个保留字。尝试用括号括起来:
I think "Index" is a reserved word. Try surrounding it with brackets:
在不知道表结构的情况下(您可以发布表的创建脚本吗?)这里有一些我会尝试的事情:
在所有列和表名称周围放置方括号([])以将它们转义,以防万一
将表的模式名称放入表中,dbo.[ConsoleUsage]而不是[ConsoleUsage]
检查 [Index] 是否为 char 字段,如果是,请使用 '912' 而不是 912
尝试稍微转换语句:
更新时间
设置总电路数 = 123
FROM dbo.[ConsoleUsage] T
其中 T.[索引] = 912
Without knowing the table structure (could you post the create script for the table?) here are a few things I would try:
put square brackets ([]) around all columns and table name to escape them out, just in case
put the schema name of the table to the table, dbo.[ConsoleUsage] instead of [ConsoleUsage]
check to see if [Index] is a char field or not, use '912' instead of 912 if it is
Try converting statement a little:
UPDATE T
SET TotalCircuits = 123
FROM dbo.[ConsoleUsage] T
WHERE T.[Index] = 912