-1

我的 sql 语句如下 insert 语句仅有效 update 和 delete 语句无效

Purchase_InvoiceNo 是 Purchase 表的主键列我像这样得到这个值并将其值插入到 PurchaseProduct 表“SELECT IDENT_CURRENT ('Purchase') AS [Purchase_InvoiceNo]”

        string deletecmd_PurchaseProduct =
            @"DELETE FROM PurchaseProduct " +
            "PurchaseProduct_No=@PurchaseProduct_No and "+
            "Purchase_InvoiceNo=@Purchase_InvoiceNo ";

        string updatcmd_PurchaseProduct =
            "UPDATE PurchaseProduct "
        + "  SET    "
        + "  PurchaseProduct_SerialNo =@PurchaseProduct_SerialNo"
        + ", Purchase_InvoiceNo =@Purchase_InvoiceNo"
        + ", ProductNo =@ProductNo"
        + " PurchaseProduct_Quantity =@PurchaseProduct_Quantity "
        + ", PurchaseProduct_Unit =@PurchaseProduct_Unit"
        + ", PurchaseProduct_Price =@PurchaseProduct_Price"
        + " Where "
        + " PurchaseProduct_No=@PurchaseProduct_No";



        string insertcmd_PurchaseProduct = "INSERT INTO PurchaseProduct" +
                           "(" +
                           " PurchaseProduct_SerialNo"+
                           ",Purchase_InvoiceNo" +
                           ",ProductNo" +
                           ",PurchaseProduct_Quantity " +
                           ",PurchaseProduct_Price" +
                           ",PurchaseProduct_Unit" +    //6
                           ")" +
                            "Values" +
                           "(" +
                           " @PurchaseProduct_SerialNo"+
                           ",@Purchase_InvoiceNo" +
                           ",@ProductNo " +
                           ",@PurchaseProduct_Quantity " +
                           ",@PurchaseProduct_Price" +
                           ",@PurchaseProduct_Unit" +       //6
                           ");";
4

1 回答 1

0

您的删除命令似乎不完整:

string deletecmd_PurchaseProduct =
            @"DELETE FROM PurchaseProduct " +
            "PurchaseProduct_No=@PurchaseProduct_No and "+
            "Purchase_InvoiceNo=@Purchase_InvoiceNo ";

应该:

string deletecmd_PurchaseProduct =
            @"DELETE FROM PurchaseProduct WHERE" +
            "PurchaseProduct_No=@PurchaseProduct_No and "+
            "Purchase_InvoiceNo=@Purchase_InvoiceNo ";

我不明白为什么INSERT应该失败,除非您插入重复的主键值或者您没有将数据插入到没有默认值的不可空字段中。

    string updatcmd_PurchaseProduct =
      "UPDATE PurchaseProduct "
    + "SET    PurchaseProduct_SerialNo = @PurchaseProduct_SerialNo, "
    + "Purchase_InvoiceNo = @Purchase_InvoiceNo, "
    + "ProductNo = @ProductNo, "
    + "PurchaseProduct_Quantity = @PurchaseProduct_Quantity, "
    + "PurchaseProduct_Unit = @PurchaseProduct_Unit, "
    + "PurchaseProduct_Price = @PurchaseProduct_Price "
    + "Where PurchaseProduct_No = @PurchaseProduct_No";

上面少了一个逗号。

于 2013-08-26T03:58:34.560 回答