我想更新DB2 / AS400表中的数据集。
问题是如果我在参数列表中有字符串参数,则命令找不到要更新的行。
例如:如果我仅使用公司编号运行命令,则命令将成功。如果我使用公司编号和设施编号运行命令,则命令失败。
有没有人有任何想法?
IDbConnection cn = Tools.GetCnApp();
try
{
StringBuilder sql = new StringBuilder();
sql.AppendLine("UPDATE " + Tools.GetSchemeApp() + "/ChangeReasonAssignments");
sql.AppendLine(" SET Confirmed = @CONF, Confirmed_By = @CONFBY, Confirmed_At = @CONFAT");
sql.AppendLine(" WHERE Company = @CONO AND Facility = @FACI AND Department = @DEPT");
sql.AppendLine(" AND Production_Group = @PRGR AND Manufacturing_Order = @ORDR AND Order_Operation = @OPER");
sql.AppendLine(" AND Confirmed = 0");
IDbCommand cmd = cn.CreateCommand();
cmd.SetParameter("@CONO", this.CompanyNumber);
cmd.SetParameter("@FACI", this.FacilityNumber);
cmd.SetParameter("@DEPT", this.ProductionGroup.Department.Name);
cmd.SetParameter("@PRGR", this.ProductionGroup.Name);
cmd.SetParameter("@ORDR", this.ManufacturingNumber);
cmd.SetParameter("@OPER", this.OperationNumber);
cmd.SetParameter("@CONFBY", Base.User);
cmd.SetParameter("@CONFAT", DateTime.Now.ToString());
cmd.SetParameter("@CONF", 1);
cmd.CommandText = sql.ToString();
if (cmd.ExecuteNonQuery() > 0)
{
}
数据库中的数据类型为:
.NET 中的数据类型为:
sql.ToString()结果:
UPDATE TSAEDBDEV/ChangeReasonAssignments SET Confirmed = @CONF, Confirmed_By = @CONFBY, Confirmed_At = @CONFAT WHERE Company = @CONO AND Facility = @FACI AND Confirmed = 0
答案 0 :(得分:0)
尝试将字符串值设置为“:cmd.SetParameter("@DEPT", "'" + this.ProductionGroup.Department.Name + "'");