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. calling a function to save to a table

calling a function to save to a table

Scheduled Pinned Locked Moved Visual Basic
helpquestion
2 Posts 2 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

    i have performed validation and populated a datagrid via a command button and using a "pseudo" (temporary) table called OrderDetails2. Now I wish to save the details to the proper table (ie OrderDetails), as every row in the datagrid as to be looped through to achieve this, I am using this code: Dim iRowCount As Integer 'Dim row As Integer iRowCount = Adodc3.Recordset.RecordCount For DataGrid2.row = 0 To iRowCount Call Save Next row the code in the save function is: Dim iOrderNumber As Integer iOrderNumber = RS.Columns("OrderNo") Dim strProductCode As String strProductCode = RS.Columns("ProductCode") Dim strProductDesc As String strProductDesc = RS.Columns("ProductDesc") Dim iProductQty As Integer iProductQty = RS.Columns("Quantity") Dim iOrderPrice As Integer iOrderPrice = RS.Columns("Price") Dim nSQL As String 'inserting the order into order detail nSQL = "Insert Into OrderDetail (OrderNo, ProductCode,ProductDesc, Quantity, Price) " & _ " Values (" & iOrderNo & ", '" & strCode & "', '" & strDesc & "', " & iQuantity & ", " & iFullPrice & ")" Set RS = Conn.Execute(nSQL) however, when run, a compile error is thrown "variable required - can't assign to this expression" (referring to the datagrid.row) what can i do to fix this or is there any different way to can achieve the same functionality? Thanking you!

    H 1 Reply Last reply
    0
    • M mcm

      i have performed validation and populated a datagrid via a command button and using a "pseudo" (temporary) table called OrderDetails2. Now I wish to save the details to the proper table (ie OrderDetails), as every row in the datagrid as to be looped through to achieve this, I am using this code: Dim iRowCount As Integer 'Dim row As Integer iRowCount = Adodc3.Recordset.RecordCount For DataGrid2.row = 0 To iRowCount Call Save Next row the code in the save function is: Dim iOrderNumber As Integer iOrderNumber = RS.Columns("OrderNo") Dim strProductCode As String strProductCode = RS.Columns("ProductCode") Dim strProductDesc As String strProductDesc = RS.Columns("ProductDesc") Dim iProductQty As Integer iProductQty = RS.Columns("Quantity") Dim iOrderPrice As Integer iOrderPrice = RS.Columns("Price") Dim nSQL As String 'inserting the order into order detail nSQL = "Insert Into OrderDetail (OrderNo, ProductCode,ProductDesc, Quantity, Price) " & _ " Values (" & iOrderNo & ", '" & strCode & "', '" & strDesc & "', " & iQuantity & ", " & iFullPrice & ")" Set RS = Conn.Execute(nSQL) however, when run, a compile error is thrown "variable required - can't assign to this expression" (referring to the datagrid.row) what can i do to fix this or is there any different way to can achieve the same functionality? Thanking you!

      H Offline
      H Offline
      Hesham Amin
      wrote on last edited by
      #2

      Set RS = Conn.Execute(nSQL) I think the above statement is the problem .. you execute a statement that inserts data in a table and does not return a recordset .. try using : Conn.Execute(nSQL)

      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