Can't get any data out from SQL database

grafix4all

Member
Licensed User
Longtime User
Sorry I'am a Newbie.
But simple code give me an error that really can't understand.
I have a simple database with two fields 'plunummer' and 'varetekst' in a table called 'drikkevare' all fields are formatted as text - i'am using Sqllitebrowser to create the database
All works fine when I create records, delete records an so on :)
But the problem is when I need to find a record based on data in field 'plunummer' and the get the data that is stored in field 'varetekst'

I'am absolutely sure that there are the right data in the table!

Her is my code:

Sub ListViewForDrikkeVarer_ItemClick (Position As Int, Value As Object)
Dim Plu As String
Dim TekstTilPlu As String
dbCursor=dbSQL.ExecQuery2("SELECT varetekst FROM drikkevarer WHERE plunummer = ?", Array As String(Value))
Plu = dbCursor.GetString ("varetekst")
dbCursor.Close

The Error is:
LastException android.database.cursorindexOutOfBoundsException: Index-1 requested, with a size of 1

Pls help
/Thomas
 

Mahares

Expert
Licensed User
Longtime User
When you create the dbCursor, you need to position the cursor to the record in question to get it. See the code I added below:

B4X:
Sub ListViewForDrikkeVarer_ItemClick (Position As Int, Value As Object)
 Dim Plu As String
 Dim TekstTilPlu As String
 dbCursor=dbSQL.ExecQuery2("SELECT varetekst FROM drikkevarer WHERE plunummer = ?", Array As String(Value))
 dbCursor.Position= 0 'will postion at the first record added by Mahares
 Plu = dbCursor.GetString ("varetekst")
 msgbox(Plu,"")
 dbCursor.Close 
End Sub
 
Upvote 0

grafix4all

Member
Licensed User
Longtime User
Problem solved

THANX Mahares
Now it works just perfect.
Thank you for the time you gave me. I really appreciate that :icon_clap:
 
Upvote 0
Top