setting a recordset field value

I know I am doing something stupid here, but I can’t figure it out :frowning:

I have a recordset that is populated from a prepared sql statement.

I then attempt to set one of the fields to another value and update the database, but the field is not being updated. in debugging it looks like the updated field value is not being set in the recordset.

passedValue is a string variable passed into this method:

        msgbox(rs.field("lastName").value)
        msgbox (passedValue)
        rs.field("lastName").value = passedValue
        msgbox(rs.field("lastName").value)

1st msgbox shows “ZAnder” (“ZAnder” is what was pulled from the DB)
2nd msgbox shows “asd” (“asd” is what was passed into the method)
3rd msgbox shows “ZAnder”

I was expecting rs.field(“lastName”).value to be “asd”

What am I doing wrong?

Try rs.field(“lastname”).stringvalue and see if that makes a difference. That’s what I use

       msgbox(rs.field("lastName").stringvalue)
        msgbox (passedValue)
        rs.field("lastName").stringvalue = passedValue
        msgbox(rs.field("lastName").stringvalue)

same result

Here is the whole method. Maybe there is something else in here that is messing it up…

I understand I may not be doing this in the most efficient way, but functionally I am expecting this method to update multiple rows in a database based on the contents of a listbox where the “entryId” field is the 1st column of the listbox passed in:
parameters to the method are as follows:

lb as Listbox
passedField as String (value passed into the method during test is “lastName”)
passedValue as string (value passed into the method during test is “asd”)

  Dim stmt As PreparedSQLStatement = Self.Prepare("SELECT entryID, lastName, firstName, MaidenName, page from entries where entryID = ?")
  Dim i as Integer
  dim rs as RecordSet
      
  for i=0 to lb.LastIndex
    stmt.BindType(0, SQLitePreparedStatement.SQLITE_INTEGER)
    stmt.Bind(0, lb.Cell(i,0))
    rs  = stmt.SQLSelect
    
    if rs <> Nil then
      if passedField="lastName" then
        msgbox(rs.field("lastName").stringvalue)
        msgbox (passedValue)
        rs.field("lastName").stringvalue = passedValue
        msgbox(rs.field("lastName").stringvalue)
        rs.update
      end if
    else
      msgbox(str(Self.ErrorCode) + ": " +Self.ErrorMessage)
    end if
  next
  
  rs.close
  Return Not Self.Error

If you are using realsqldatabase then you need to execute ‘rs.edit’ before changing the field value.

Argh… Thank you Simon. I knew it was something stupid…

That applies to any database, not just realsqldatabase.

I read that the new SQLIteDatabase does not need the rs.Edit command any more which is why I mentioned it specifically.

I forgot about other databases!

I’m not sure what you read, but rs.Edit is needed to edit a RecordSet for any database, including SQLiteDatabase.

Ok, I stand corrected.

Thanks, Paul.