RowSet.Editrow nothing happens

Hello,

I’m trying to make changes in the database using RowSet.Editrow. Connection Ok., Querying data is OK. But changing it using the following code is not possible. Nothing happens. No error

var rs as RowSet
rs = SQLiteDatabase1.SelectSQL(“SELECT f1, f2 from t1 where f1 = ‘test1’;” )

rs.EditRow
rs.Column(“f1”).StringValue = “test2”

rs.SaveRow
rs.Close

thanks
Musti

to use editrow, you must have a primary key in the table, and you must select this primary key in your query.
you can also use a sqlexecute and use the sql UPDATE command.

1 Like

f1 is primary key

what is in sqlitedatabase1.errorcode after the selectsql ?
how many row(s) found inside rs ?

It’s possibly because you are modifying the primary key.

You could try using a column alias to retrieve a second copy of the column which you then modify.

Something like this…

var rs as RowSet
rs = SQLiteDatabase1.SelectSQL("SELECT f1, f1 AS f1b, f2 from t1 where f1 = 'test1';")

rs.EditRow
rs.Column("f1b").StringValue = "test2"
rs.SaveRow

rs.Close

if I just want to change f2, nothing happens
f2 not primary key

Create an example project, zip it together and upload it to the forum.
Someone will review.

1 Like

Not me, I never use EditRow.

I would have done:

SQLiteDatabase1.ExecuteSQL ("update t1 set f1b = ? where f1 = 'test1'", "test2")
1 Like

see the info at warning
https://documentation.xojo.com/api/databases/rowset.html#rowset-saverow

check if you are in the right database and connected.
try using CommitTransaction (i had to use for postgres somehow)

use
rs = SQLiteDatabase1.SelectSQL("SELECT f1, f2 from t1 where f1 = ?", "test1" )

try naming PK with ID

subclass this SQLiteDatabase to have more control.

2 Likes