Examples: UpdateRow method

This agent changes the value of a row and column specified by the user.

Uselsx "*LSXODBC"
Sub Initialize
  Dim con As New ODBCConnection
  Dim qry As New ODBCQuery
  Dim result As New ODBCResultSet
  Dim msg As String
  Set qry.Connection = con
  Set result.Query = qry
  con.ConnectTo("ATDB")
  qry.SQL = "SELECT * FROM STUDENTS ORDER BY LASTNAME"
  result.Execute
  result.LastRow
  currentRow = Inputbox _
  ("Which row do you want to change?", "Which row?")
  If currentRow = "" Then
    Messagebox "No value entered for row",, "Bad row"
    Exit Sub
  End If
  If currentRow < 1 Or currentRow > result.NumRows Then
    Messagebox "Row out of range",, "Bad row"
    Exit Sub
  End If
  result.CurrentRow = currentRow
  For i = 1 To result.NumColumns
    msg = msg & "  " & result.GetValue(i)
  Next
  currentColumn = Inputbox(msg, "Which column?")
  If currentColumn = "" Then
    Messagebox _
    "No value entered for column",, "Bad column"
    Exit Sub
  End If
  If currentColumn = "" Or currentColumn < 1 _
  Or currentColumn > result.NumColumns Then
    Messagebox "Column out of range",, "Bad column"
    Exit Sub
  End If
  newValue = Inputbox$("Enter new value", "SetValue", _
  result.GetValue(Cint(currentColumn)))
  If newValue = "" Then
    Messagebox "No value entered"
    Exit Sub
  End If
  Call result.SetValue(Cint(currentColumn), newValue)
  result.UpdateRow
  result.Close(DB_CLOSE)
  con.Disconnect
End Sub