Updating data using recordsets

I'm trying to use recordsets to update my tables.  The following seems to run ok, but doesn't update my data.  I've been through the manual and wiki examples, and my code seems to be the same as published.  Has anyone had this issue?  My code is below, simply to update the elevation in the point table to 35.  I'm happy my sql query is correct and the recordset is opening.  Thanks

Dim sSql As String
Dim data As Recordset

sSql = "select * from [POINT]"

Set data = gINTRules.CurrentProject.OpenRecordset(sSql, dbOpenDynaset)

With data
Do Until .EOF
  .Edit
  data("Elevation")=35
  .Update
  .MoveNext
Loop
End With

data.Close

I've also tried the following which runs, but again doesn't update.
data!Elevation = 35
.Fields("Elevation") = 35

 

 

Parents
  • Which gINT rules event calls the code?...it can't be On Save.  In gINT INPUT, can you move off the table then back to POINT and see the new data after it calcs?

    Phil Wade
    Datgel
    Bentley Channel Partner and Developer Partner
    E: phil.wade@datgel.com | T: +61 2 8202 8600 & +65 6631 9780

    Get the most out of gINT with Datgel Tools.

  • At the moment I'm just pressing play within the gINT rules editor, ie, not using an event.

    I have tried to move off the table to refresh it, but the values are still not there.

  • I don't develop in SAX basic much these days, but I don't recall being able to run code from the editor like you are attempting.

    I suggest you call the code using the After Save table event, and you will need to call the refresh grid gINT Rules method(?).  I have found the refesh grid methods are hit and miss, very fustrating as a developer when something works only part of the time.

    Phil Wade
    Datgel
    Bentley Channel Partner and Developer Partner
    E: phil.wade@datgel.com | T: +61 2 8202 8600 & +65 6631 9780

    Get the most out of gINT with Datgel Tools.

  • There are many different programming styles that will work for gINT Rules, below is one style. It took longer to write this description up than it took to create the code that works. Again, this is just one suggestion as to what might work for you.

    I used GRA005 to create the skeleton code for the PopulateElevation procedure. Then, all I did was add my "code" to assign a value of 35 which is highlighted in yellow.

    In addition, this follows the programming style as discussed in the gINT Rules manual and references an additional module called "auxillary procedures" and includes the Public Sub Main procedure.

    The "PopulateElevation" procedure is then assigned to the "gINT Rules Procedure on Save" Table Event.

    You can run the procedure while you are in the gINT Rules editor using the F5 command, which is sounds like you are already doing with your code.

     

    '#LibInclude "auxillary procedures"

    Option Explicit

    Public Sub Main
      With gINTRules.GridData

        'Put the grid data into a working string data array.
        gsDataA = .DataArray
        glNumRows = UBound(gsDataA, 2)
        CallByName Me, gINTRules.ProcedureName, vbMethod

        'Put the modified data array back into the input grid.
        .DataArray = gsDataA

        'Success is True if there were no errors.
        gINTRules.Success = CBool(.ErrorCol = 0)

      End With
    End Sub

    Public Sub PopulateElevation
    '*****************************************************
    '17Apr2013 DK
    'Description:
    '  This procedure is used to populate the Elevation field with
    '  a set value.
    '*****************************************************

      Const s_Field_BoreholeID As String = "PointID"
      Const s_Field_Elevation As String = "Elevation"

      Dim dElevation As Double

      'Column positions of fields in the data array.
      Dim iPsBoreholeID As Integer
      Dim iPsElevation As Integer

      Dim lRow As Long

      Dim sBoreholeID As String
      '------------------------

      'Obtain pointers to the field data within the data array.
      If InitFieldsFnB(s_Field_BoreholeID, iPsBoreholeID, _
                       s_Field_Elevation, iPsElevation) _
      Then
        'One or more of the required fields missing from the table.
        Exit Sub
      End If

      With gINTRules.GridData
        For lRow = 1 To glNumRows
          sBoreholeID = gsDataA(iPsBoreholeID, lRow)

          dElevation = 35

          gsDataA(iPsElevation, lRow) = CStr(dElevation)
        Next lRow
      End With
    End Sub

Reply
  • There are many different programming styles that will work for gINT Rules, below is one style. It took longer to write this description up than it took to create the code that works. Again, this is just one suggestion as to what might work for you.

    I used GRA005 to create the skeleton code for the PopulateElevation procedure. Then, all I did was add my "code" to assign a value of 35 which is highlighted in yellow.

    In addition, this follows the programming style as discussed in the gINT Rules manual and references an additional module called "auxillary procedures" and includes the Public Sub Main procedure.

    The "PopulateElevation" procedure is then assigned to the "gINT Rules Procedure on Save" Table Event.

    You can run the procedure while you are in the gINT Rules editor using the F5 command, which is sounds like you are already doing with your code.

     

    '#LibInclude "auxillary procedures"

    Option Explicit

    Public Sub Main
      With gINTRules.GridData

        'Put the grid data into a working string data array.
        gsDataA = .DataArray
        glNumRows = UBound(gsDataA, 2)
        CallByName Me, gINTRules.ProcedureName, vbMethod

        'Put the modified data array back into the input grid.
        .DataArray = gsDataA

        'Success is True if there were no errors.
        gINTRules.Success = CBool(.ErrorCol = 0)

      End With
    End Sub

    Public Sub PopulateElevation
    '*****************************************************
    '17Apr2013 DK
    'Description:
    '  This procedure is used to populate the Elevation field with
    '  a set value.
    '*****************************************************

      Const s_Field_BoreholeID As String = "PointID"
      Const s_Field_Elevation As String = "Elevation"

      Dim dElevation As Double

      'Column positions of fields in the data array.
      Dim iPsBoreholeID As Integer
      Dim iPsElevation As Integer

      Dim lRow As Long

      Dim sBoreholeID As String
      '------------------------

      'Obtain pointers to the field data within the data array.
      If InitFieldsFnB(s_Field_BoreholeID, iPsBoreholeID, _
                       s_Field_Elevation, iPsElevation) _
      Then
        'One or more of the required fields missing from the table.
        Exit Sub
      End If

      With gINTRules.GridData
        For lRow = 1 To glNumRows
          sBoreholeID = gsDataA(iPsBoreholeID, lRow)

          dElevation = 35

          gsDataA(iPsElevation, lRow) = CStr(dElevation)
        Next lRow
      End With
    End Sub

Children
No Data