我正在使用VB.Net 2015,並使用MS Access DataBase。 我有了很多的項目,例發票編號2一張發票有橘子,蘋果和香蕉,當使用如何在VB.Net中更新具有相同ID的項目
"UPDATE Item_Invoice SET [email protected]_Name,[email protected]_Type,[email protected]_Quantity,[email protected]_Purchase_Price,[email protected]_Total_Cost Where Invoice_No=" & CInt(txtInvoiceNo.Text) & " " , all items become Lemon.
所有項目視圖發票號碼2在DataGrid和DataGrid中更改香蕉項檸檬成爲檸檬,由於Update語句使用Invoice_No 2更新所有項目,任何想法如何克服和解決問題。由於提前
For i = 0 To DGPurchase.Rows.Count - 2
ObjCommand.Parameters.Clear()
ObjCommand.CommandText = "UPDATE Item_Invoice SET [email protected]_Name,[email protected]_Type,[email protected]_Quantity,[email protected]_Purchase_Price,[email protected]_Total_Cost Where Invoice_No=" & CInt(txtInvoiceNo.Text) & " "
ObjCommand.Connection = myConnection
ItmName = DGPurchase.Rows(i).Cells(0).Value.ToString
ItmType = DGPurchase.Rows(i).Cells(1).Value.ToString
ItmQuantity = CDbl(DGPurchase.Rows(i).Cells(2).Value)
itmTotalCost = CDbl(DGPurchase.Rows(i).Cells(3).Value)
ItmPurPrice = CDbl(DGPurchase.Rows(i).Cells(4).Value)
ObjCommand.Parameters.AddWithValue("Item_Name", ItmName)
ObjCommand.Parameters.AddWithValue("Item_Type", ItmType)
ObjCommand.Parameters.AddWithValue("Item_Quantity", ItmQuantity)
ObjCommand.Parameters.AddWithValue("Item_Total_Cost", itmTotalCost)
ObjCommand.Parameters.AddWithValue("Item_Purchase_Price", ItmPurPrice)
' ObjCommand.Parameters.AddWithValue("Invoice_No", InvNo)
ObjCommand.ExecuteNonQuery()
'ObjCommand.Dispose()
Next I
你能粘貼你的表結構,好嗎?這將是有用的 –
嗯..我想你應該添加你想要改變你的條款 – Pikoh
你的項目名稱是最困難的方式可能。如果您使用的是DGV,那麼也可以使用DataTable和DataAdapter。然後它就是'myDA.Update(myDT)'來更新任何需要更新的東西。 DB Provider對象完成所有工作。你也應該參加[遊覽]。 – Plutonix