Android Question Database Error

DawningTruth

Active Member
Licensed User
I am learning how to use SQLite and DbUtils.

I have written code that creates a db and a table. It then writes values to the table. However it does not seem to be able to retrieve them. Not too sure what is wrong with the code, as it is pretty much what is in the tutorial video.

Here is the code:

B4X:
//Create Table
DBUtils.CreateTable(sql1, "tbl_User", CreateMap( _
        "cl_Parameter" : DBUtils.DB_TEXT, _
        "cl_Value" : DBUtils.DB_TEXT), _
        "cl_Parameter")
  
//Insert Values
Dim rows As List
rows.Initialize
Dim row As Map
  
row = CreateMap("cl_Parameter" : "name", "cl_Value" : "John")
rows.Add(row)
row = CreateMap("cl_Parameter" : "surname", "cl_Value" : "Williams")
rowS.Add(row)
  
DBUtils.InsertMaps(sql1,"tbl_User", rows)

//Read Inserted Values
Dim queryResult As ResultSet = sql1.ExecQuery("SELECT cl_Parameter, cl_Value FROM tbl_Parameters")
Log(queryResult.GetString("cl_Parameter"))
Log(queryResult.GetString("cl_Value"))

I get this error:

android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 2

Any suggestions?
 

Brandsum

Well-Known Member
Licensed User
Where did you get this error? I mean which line?
Check if it works like this
B4X:
Do While queryResult.NextRow
    Log(queryResult.GetString("cl_Parameter"))
    Log(queryResult.GetString("cl_Value"))
Loop
 
Last edited:
Upvote 0

DawningTruth

Active Member
Licensed User
Where did you get this error? I mean which line?
Check if it works like this
B4X:
Do While queryResult.NextRow
    Log(queryResult.GetString("cl_Parameter"))
    Log(queryResult.GetString("cl_Value"))
Loop
Thx Brandsum I will try that.

The error is on the lines:

B4X:
Log(queryResult.GetString("cl_Parameter"))
Log(queryResult.GetString("cl_Value"))
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
It has been a while since I've played with dbUtils but if I recall the columns names must be in lower-case, try
B4X:
Log(queryResult.GetString("cl_parameter"))
Log(queryResult.GetString("cl_value"))
 
Upvote 0
Top