SQlite error

On this code, I keep getting the error message “The current row is not editable (out of range)”. Never had this message before? The SQL string is valid, I checked that in the debugger.

[code] dim sqlString as String
dim NPrs as RecordSet

sqlString = “select * from CDD2_Person where P_VORNAME = '” + EscapeQuotes(mainwindow.nameField.text) + “’ and P_NACHNAME = '” _

  • EscapeQuotes(mainWindow.ChristiannameField.text) + “’”

NPrs = cdd2.db.sqLSelect(sqlString)

if NPrs <> nil then
MsgBox(“Person schon in Datenbank”)
end if

if cdd2.db.Error then
msgBox("Datenbank Fehler: " + CDD2.db.errorMessage)
end if

return[/code]

Another thing is: what happens to RS if the method ends. Is it kept alive? Is it cleaned up? Do you have to call Rs.close? Does that remove the recordset object from memory? Questions, questions.

Vorname und Christianname are both the same und NACHNAME is ‘cash on delivery’ (dutch: 'rembours). this sql query looks a bit strange. Maybe that’s causing confusion further on in your program.

Supposing that the code you showed, is meant to be in a method then as soon as the method is returning to the calling routine the recordset is ‘out of scope’ and will be nil.

Well, how the fields and columns are called is of no concern. You can give it any name you want.

But your last sentence… The code is in an LostFocus event. I do not understand the Out of Scope thing. What does it actually mean?

You declared the recordset within this routine with the dim statement and filled it with records if the query gave record(s) back, but the scope of the recordset is from the moment you dim it in your code until the (sub)routine/method/event ends. As soon as the return statement is executed the routine is over and the variables dimmed in that routine are nilled.
The same situation do you have when you dim a variable within a loop or a if-end if construction, as soon as these loop or if-end if construction end, the variables don’t exist anymore.

Ok clear. Thanks

I’m not sure why you are not checking to see if there is a record there. Let’s say I have a table … tableA with a column … columnA

Select columnA from tableA where columnA = ‘hello world’

If hello world doesn’t exist in tableA where is my error? I don’t have one, a recordset is returned BUT there are no records in it ergo. That’s how you are testing. You must check to see if there is a record. If it’s not Nil, there isn’t an error.

.[quote=21311:@Jym Morton]If hello world doesn’t exist in tableA where is my error? I don’t have one, a recordset is returned BUT there are no records in it ergo. That’s how you are testing. You must check to see if there is a record. If it’s not Nil, there isn’t an error.[/quote]

That is exactly what happened. An empty recordset. But what happens now is:

If a certain field is losing focus, the table is checked for existance of the name. I changed the code:

[code] dim sqlString as String
dim rs as RecordSet

sqlString = “select * from CDD2_Person where P_VORNAME = '” + EscapeQuotes(mainwindow.nameField.text) + “’ and P_NACHNAME = '” _

  • EscapeQuotes(mainWindow.ChristiannameField.text) + “’”

rs = cdd2.db.sqLSelect(sqlString)

if rs <> nil then
if rs.recordCount > 0 then
msgbox(“Hier data person invoegen”)
end if
else
if cdd2.db.Error then
msgBox("Datenbank Fehler: " + CDD2.db.errorMessage)
end if
end if
[/code]

I get in this code no more Out of scope errors. But… if I save the record this error is back again… Don’t get it…

The error is where you saved the record I’m guessing. You can’t get an Out of Scope error from a select statement. The error is just held until a transaction is ended. You’d have to post your saving the record code.

I see in the debugger that this error is in the database before I run the above code. So whenever I do this error check, the error pops up. I suspect it is caused by something else, but what?

Found it! As far as I can see remains the errorcode into the database until shown. I ran an update query on another table which caused the error. After removal of this query the problems where gone. Pfewww…

Thanks for all your help and suggestions…