complicated question re editing datagrid
-
uSQL = "Insert Into OrderDetails2 (OrderNumber, ProductCode, ProductDesc, Quantity, Price) " & _ " Values (" & iOrderNo & ", '" & strCode & "', '" & strDesc & "', " & iQuantity & ", " & iUnitPrice & "," & iFullPrice & ")" Set RS = Conn.Execute(uSQL) Me.Adodc3.Refresh Me.DataGrid2.Refresh the above code is used to populated the datagrid first time round, by the click event of a command button. Price relates to UnitPrice*Quantity, which is calculated prior to the population of the grid, on the click of a command button. i cant edit the quantity in the datagrid directly due to the calculation that is required for FullPrice (ie Qty * Price). so instead i change the quantity in the datagrid (all other columns except FullPrice are set to locked) and press an "Edit" button which contains the following code: Dim strCustomerCode As String iOrderNo = txtOrderNo.Text strCustomerCode = Me.txtCustomerCode.Text strProductCode = DataGrid2.Columns("ProductCode") DataGrid2.Columns("ProductCode").Locked = True DataGrid2.Columns("ProductDesc").Locked = True iPrice = Datagrid2.Columns("UnitPrice") Dim iGridQty As Integer DataGrid2.Columns("Quantity") = iGridQty iFullPrice = iPrice * iGridQty DataGrid2.Columns("Price") = iFullPrice DataGrid2.Columns("Price").Locked = True With Adodc3.Recordset Dim editSQL As String editSQL = "Update OrderDetails2 " & _ " Set OrderDetails2.Quantity = " & iGridQty & ", " & _ " OrderDetails2.Price = " & iFullPrice & " " & _ " where OrderDetails2.ProductCode = '" & strProductCode & "' AND OrderDetails2.OrderNumber = " & iOrderNo & "" Set RS = Conn.Execute(editSQL) End With MsgBox ("Record Updated") The record updates fine in the table but when i leave the datagrid ,i get the following error message: "Cannot be updated for updating. Some values may have been changed sinse it was last read". What am i doing wrong? If you need any more information or explanation, please let me know - any help would be greatly appreciated!