Android Question Database Error

Discussion in 'Android Questions' started by DawningTruth, Jun 27, 2019.

  1. DawningTruth

    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:

    Code:
    //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?
     
  2. Brandsum

    Brandsum Active Member Licensed User

    Where did you get this error? I mean which line?
    Check if it works like this
    Code:
    Do While queryResult.NextRow
        
    Log(queryResult.GetString("cl_Parameter"))
        
    Log(queryResult.GetString("cl_Value"))
    Loop
     
    Last edited: Jun 27, 2019
  3. DawningTruth

    DawningTruth Active Member Licensed User

    Thx Brandsum I will try that.

    The error is on the lines:

    Code:
    Log(queryResult.GetString("cl_Parameter"))
    Log(queryResult.GetString("cl_Value"))
     
  4. Jeffrey Cameron

    Jeffrey Cameron Active Member Licensed 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
    Code:
    Log(queryResult.GetString("cl_parameter"))
    Log(queryResult.GetString("cl_value"))
     
    DawningTruth likes this.
  5. DawningTruth

    DawningTruth Active Member Licensed User

    Thx
     
  6. DawningTruth

    DawningTruth Active Member Licensed User

    Thx Brandsum, this works.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice