【发布时间】:2019-01-17 14:57:48
【问题描述】:
我正在尝试使用以下查询更新 TableA,但它给了我一个错误 “IBM.Data.DB2.iSeries.iDB2SQLErrorException:'SQL0104 令牌 CNUM 无效。有效令牌:使用 SKIP WAIT WITH FETCH LIMIT ORDER WHERE OFFSET”。虽然我可以在 DB2 中使用相同的查询来更新数据库。
using (IDbCommand command = this.connection.CreateCommand())
{
command.CommandText = string.Format(
@"UPDATE {0}.TableA
SET
STS = @Status,
USR = @User
WHERE
CNUM = @CNum", CoreServer.CoreCollection);
IDbDataParameter statusParam = CoreServer.CreateParameter(command, "@Status", string.Empty, 3);
IDbDataParameter UserParam = CoreServer.CreateParameter(command, "@User", string.Empty, 50);
IDbDataParameter cNumberParam = CoreServer.CreateParameter(command, "@CNum", string.Empty, 30);
statusParam.Value = CoreServer.ConvertToDatabase(input.Status);
UserParam.Value = input.User == null ? null : input.User.Trim();
cNumberParam.Value = input.CNumber.Trim();
iDB2Command db2Command = (iDB2Command)command;
db2Command.Transaction = (iDB2Transaction)transaction;
db2Command.ExecuteNonQuery();
}
其他插入和选择查询适用于同一个表
【问题讨论】:
-
CNUM 列代表什么?
-
字符串数据类型表的主键
-
所以,根据这个 IBM Documentation:应用程序生成了一个语法错误的 SQL 语句。如需帮助确定问题,请使用 ODBC 管理器随附的 ODBC 跟踪工具查看 SQL.LOG。
-
我建议查看 .log 文件以检查生成的 SQL 是否具有正确的语法。
-
CoreServer.CreateParameter是做什么的?