我的sql语句如下 insert语句只能起作用 更新和删除语句不起作用
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
");";
答案 0 :(得分: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";
上面有一个丢失的逗号。