如果我尝试更新所有字段,则更新失败,但如果我更新所有字段,则更新失败

时间:2018-01-25 15:32:51

标签: c# sql mvvm

这有效

   UPDATE `n2000`.`orders`
    SET `OrderType` = @OrderType, `prtID` = @prtID, `ReqRef` = @ReqRef, `DateOrdered` = @DateOrdered,
    `orderETA` = @orderETA, `DateRcvd` = @DateRcvd, `Status` = @Status, `ShipCost` = @ShipCost,
    `Duties` = @Duties, `Currency` = @Currency, `Conv` = @Conv, `Terms` = @Terms,
    `Shipping` = @Shipping, `BuyerID` = @BuyerID, `ShipTo` = @ShipTo, `Notes1` = @Notes1,
    `Notes2` = @Notes2, `Notes3` = @Notes3
    WHERE `ordID` = @ordID;
    ";

这不是。

UPDATE `n2000`.`orders`
SET `OrderType` = @OrderType, `prtID` = @prtID, `ReqRef` = @ReqRef, `DateOrdered` = @DateOrdered,
`orderETA` = @orderETA, `DateRcvd` = @DateRcvd, `Status` = @Status, `ShipCost` = @ShipCost,
`Duties` = @Duties, `Currency` = @Currency, `Conv` = @Conv, `Terms` = @Terms,
`Shipping` = @Shipping, `BuyerID` = @BuyerID, `ShipTo` = @ShipTo, `Notes1` = @Notes1,
`Notes2` = @Notes2, `Notes3` = @Notes3, `legacyID` = @legacyID
WHERE `ordID` = @ordID;
";

由于某种原因,添加最后一个值legacyID会中断整个更新,然后表中没有正确更新。有谁知道这个的原因?表中的下一个值是来自不同表的左连接值,如果这会产生影响。 legacyID不是来自不同的表。

选择通话

            LoadTableQuery.Qry = @"
SELECT `orders`.`ordID`,
    `orders`.`OrderType`,
    p1.`Name`,
    `orders`.`prtID`,
    `orders`.`ReqRef`,
    `orders`.`DateOrdered`,
    `orders`.`orderETA`,
    `orders`.`DateRcvd`,
    `orders`.`Status`,
    `orders`.`ShipCost`,
    `orders`.`Duties`,
    `orders`.`Currency`,
    `orders`.`Conv`,
    `orders`.`Terms`,
    `orders`.`Shipping`,
    `orders`.`BuyerID`,
    `orders`.`ShipTo`,
    `orders`.`Notes2`,
    `orders`.`Notes3`,
    `orders`.`legacyID`,
    p1.`Address`,
    p1.`City`,
    p1.`StateProv`,
    p1.`PostalZip`,
    p1.`Tel`,
    p1.`Contact`,
    p1.`Email`,
    p1.`OrderTaxPc`,
    p2.`To`,
    p2.`Address`,
    p2.`City`,
    p2.`Prov`,
    p2.`PostalCode`,
    p2.`ContactTel`,
    p2.`C/O`
FROM
  `n2000`.`orders`
LEFT JOIN
  `n2000`.`prt`      AS p1
    ON  (orders.prtID = p1.prtID)
LEFT JOIN
  `n2000`.`shipto`      AS p2
    ON  (orders.ShipTo = p2.Ref)

";

SQL Table

UpdateTable名为

public void UpdateTable(TableQuery query, DataTable tbl)
{
    if (query.Qry != "")
    {
        if (IsConnOpen)
        {
            try
            {
                UpdateCmd.Parameters.Clear();
                UpdateCmd.CommandText = query.Qry;
                for (int i = 0; i < query.Prms.Count; i++)
                {
                    UpdateCmd.Parameters.Add(new MySqlParameter());
                    UpdateCmd.Parameters[i].ParameterName = "@" + query.Prms[i].Col;
                    UpdateCmd.Parameters[i].SourceColumn = query.Prms[i].Col;
                }
                DA.Update(tbl);
            }
            catch (MySqlException ex)
            {
                Msg = "Error: " + ex.Number + " " + ex.Message + " from Qry = " + query.Qry;
            }
            catch (Exception ex)
            {
                Msg = "Error: " + ex + " " + ex.Message;
            }
        }
        else
        {
            Msg = "Not Connected";
        }
    }
}

0 个答案:

没有答案