SQL:Update不会影响任何行

时间:2011-07-29 08:34:02

标签: sql db2-400 idbcommand

我想更新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)
    {
    }

修改

数据库中的数据类型为:

  • 公司:INTEGER
  • 设施:VARCHAR
  • Dpartment:VARCHAR
  • Production_Group:VARCHAR
  • Manufacturing_Order:INTEGER
  • Order_Operation:INTEGER

.NET 中的数据类型为:

  • CompanyNumber:int
  • FacilityNumber:String
  • 部门名称:字符串
  • ProductionGroup:String
  • Manufacturingorder:int
  • OrderOperation:int

sql.ToString()结果:

UPDATE TSAEDBDEV/ChangeReasonAssignments SET Confirmed = @CONF, Confirmed_By = @CONFBY, Confirmed_At = @CONFAT WHERE Company = @CONO AND Facility = @FACI AND Confirmed = 0

1 个答案:

答案 0 :(得分:0)

尝试将字符串值设置为“:cmd.SetParameter("@DEPT", "'" + this.ProductionGroup.Department.Name + "'");