Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. complicated question re editing datagrid

complicated question re editing datagrid

Scheduled Pinned Locked Moved Visual Basic
helpquestioncssannouncement
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mcm
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups