我正在使用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