2013-08-26 104 views
-1

我的SQL statments如下 插入語句只 update和delete語句不工作DataAdapter.Update()不起作用更新

Purchase_InvoiceNo是採購表 的主鍵列我得到這個值這樣並插入其值設置爲PurchaseProduct表 「SELECT IDENT_CURRENT( '購買')AS [Purchase_InvoiceNo]」

 string deletecmd_PurchaseProduct = 
      @"DELETE FROM PurchaseProduct " + 
      "[email protected]_No and "+ 
      "[email protected]_InvoiceNo "; 

     string updatcmd_PurchaseProduct = 
      "UPDATE PurchaseProduct " 
     + " SET " 
     + " PurchaseProduct_SerialNo [email protected]_SerialNo" 
     + ", Purchase_InvoiceNo [email protected]_InvoiceNo" 
     + ", ProductNo [email protected]" 
     + " PurchaseProduct_Quantity [email protected]_Quantity " 
     + ", PurchaseProduct_Unit [email protected]_Unit" 
     + ", PurchaseProduct_Price [email protected]_Price" 
     + " Where " 
     + " [email protected]_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 
          ");"; 
+1

你有什麼錯誤嗎?如果是這樣,他們是什麼? –

回答

0

你刪除命令似乎是不完整的:

string deletecmd_PurchaseProduct = 
      @"DELETE FROM PurchaseProduct " + 
      "[email protected]_No and "+ 
      "[email protected]_InvoiceNo "; 

應該是:

string deletecmd_PurchaseProduct = 
      @"DELETE FROM PurchaseProduct WHERE" + 
      "[email protected]_No and "+ 
      "[email protected]_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"; 

有上面缺少逗號。

+0

INSERT不會失敗 更新確實失敗 – deva

+0

請參閱上面編輯的答案。該更新似乎缺少一個逗號。 –