Error with add record

I’m new to using Xojo databases and I have built a SQLite Db for books. The routine I use for adding a single book works fine the first time but adding a 2nd book yields the error, “The current row in the RecordSet is not editable (out of range).”

The curious thing is that the routine I used to initially populate the Db from a listbox is essentially the same as this one below that fails.

[code]// Add a new row to the DB
// Reload the list

Dim s As String
Dim newBook As New DatabaseRecord

newBook.Column(“AuthorFirst”) = AuthorFirst
newBook.Column(“AuthorLast”) = AuthorLast
newBook.Column(“Title”) = Title
newBook.Column(“Notes”) = Notes + " " + s
newBook.Column(“Subject”) = Subject
newBook.Column(“PickupDate”) = PickupDate

app.db.InsertRecord(“Books”, newBook)

If app.DBError Then
MsgBox "DB Error: " + app.db.ErrorMessage
Return
End If

BooksRead.refreshListbox
[/code]

What is your table definition?

Table definition as follows…

ID integer
AuthorLast text
AuthorFirst text
Title text
Notes text
Subject text
PickupDate text
HoldDate text

[quote=141712:@Brent Malcolm]I’m new to using Xojo databases and I have built a SQLite Db for books. The routine I use for adding a single book works fine the first time but adding a 2nd book yields the error, “The current row in the RecordSet is not editable (out of range).”
[/quote]
This error usually relates to EDIT being called on a row in a reforest but that doesn’t seem to be related to the code you posted

Missing the primary key in the definition of the ID field:

ID integer PRIMARY KEY,
AuthorLast TEXT,
AuthorFirst TEXT,

What would happen if you explicitly did a Commit on the database after each InsertRecord?

Is ID an auto increment primary key? If not, it should be.

Yes the ID is an auto increment primary key.

Adding a Commit after the InsertRecord yields the same error.

Ok, I see three things that I find questionable but without seeing the whole method I can’t quite say if any are the cause.

[quote=141712:@Brent Malcolm]

newBook.Column("AuthorFirst") = AuthorFirst newBook.Column("AuthorLast") = AuthorLast newBook.Column("Title") = Title newBook.Column("Notes") = Notes + " " + s newBook.Column("Subject") = Subject newBook.Column("PickupDate") = PickupDate[/quote]
First, are the values actual strings or fields holding the strings? E.g., should ‘AuthorFirst’ be ‘AuthorFirst.Text’ and so on?
Second, what is the value of ‘s’? You’re assigning ‘Notes + " " + s’ but ‘s’ has no value. If can’t be from a passed parameter since you Dim the variable at the top of the method.

[quote=141712:@Brent Malcolm]

[code] If app.DBError Then
MsgBox "DB Error: " + app.db.ErrorMessage
Return
End If

BooksRead.refreshListbox
[/code][/quote]
Third, what is DBError? Did you mean 'app.db.Error?

And as a final thought, are any of the fields, other than the primary key, set to UNIQUE to prevent duplicates? If so, are you possible trying to add a value that already exists in that row?

I would set a breakpoint at the start of the method and step through it to see exactly where the problem crops up. As Norman pointed out earlier, the error message you are getting is typically from an Edit not an Insert.

  • Dale

Thanks to all. Found the problem by stepping through and realized I hadn’t initialized all variables for second iteration.