我必須部署在VB.NET和Visual Studio 2005中開發的VB.NET應用程序。客戶正在使用SQL Server 2008,而應用程序是針對SQL Server 2000構建的。在針對SQL Server 2008運行時插入語句失敗
我收到針對SQL Server 2008中的以下錯誤:
當使用列列表只能被指定爲「Outgoing_Invoice」標識列一個明確的價值和身份插入接通
這裏是我的兩個表中插入數據查詢:
Dim cmd1 As New SqlCommand("Insert into Stock values(@invoice_no, @gate_pass, @exp_no, @clm_no, @category, @item_name, @weight, @units_case, 0, 0, @crtns_removed, @pieces_removed, 0, 0, @date_added, @date_removed, @inc_total_price, @out_total_price, @discount, @amount, 'Sold', @expiry_date) Insert into Outgoing_Invoice values(@invoice_no, @exp_no, @party_name, @party_code, @city, @contact, @category, @item_name, @weight, @units_case, @crtns_issued, @pieces_issued, @crtns_removed, @pieces_removed, 0, 0, @scheme, @unit_price, @out_total_price, @discount, @amount, @date_removed, @expiry_date, @order_booker, @salesman)", con)
該錯誤消息顯示在cmd1.executenonquery
。這兩個表Stock
和Outgoing_Invoice
在@invoice之前都有一個標記爲serial的標識列。
僅當在SQL Server 2008上嘗試插入時纔會出現此問題。對SQL Server 2000運行時,它按預期工作。
這個問題可能的原因是什麼?如何解決?
@ user944591 - 您不能依賴訂購(答案已更新)。當不插入_all_列時,您必須**指定列名稱。 – Oded 2012-01-28 20:55:08