开发者

SQL: Update does not affect any row

I want to update a dataset in a DB2/AS400 table.

The problem is if I there is string parameter in the parameters list the command does not find a row to update.

For example: If I run the command only with the company number the command will succeed. If I run the command with the company number and facility number the command fails.

Does anyone have any idea?

IDbConnection cn = Tools.GetCnApp();

try
{
    StringBuilder sql = new StringBuilder(); 

    sql.AppendLine("UPDATE " + Tools.GetSchemeApp() + "/ChangeReasonAssignments");
    sql.Appen开发者_运维知识库dLine("  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)
    {
    }

EDIT

The datatypes in database are:

  • Company: INTEGER
  • Facility: VARCHAR
  • Dpartment: VARCHAR
  • Production_Group: VARCHAR
  • Manufacturing_Order:INTEGER
  • Order_Operation: INTEGER

The datatypes in .NET are:

  • CompanyNumber: int
  • FacilityNumber: String
  • Departmentname: String
  • ProductionGroup: String
  • Manufacturingorder: int
  • OrderOperation: int

sql.ToString() results:

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


Try to set the string values into ': cmd.SetParameter("@DEPT", "'" + this.ProductionGroup.Department.Name + "'");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜