Android Question How to Insert into SQLite from ListView_ItemClick

Frank Cazabon

Member
Licensed User
Longtime User
Hi,

I'm pretty new to this and have got stuck trying to store the selected List Value from a ListView into a SQLite table.

This is my code:

B4X:
Sub lvwRoutes_ItemClick (Position As Int, Value As Object)
    Dim Query As String
    Query = "INSERT INTO SelectedRoute (srt_name) VALUES (Value)"
    Main.SQLLite.ExecNonQuery(Query)
End Sub

But I get this run time error:

android.database.sqlite.SQLiteException: no such column: Value (code 1): , while compiling: INSERT INTO SelectedRoute (srt_name) VALUES (Value)

My table was created like this:

B4X:
    Query = "CREATE TABLE SelectedRoute (srt_name text null)"
    SQLLite.ExecNonQuery(Query)

Am I using incorrect syntax in the INSERT statement or do I need to do something with the Value object before trying to insert it?
 

Frank Cazabon

Member
Licensed User
Longtime User
LOL, I think I see the problem:

I need to build the query string like this -

B4X:
Query = "INSERT INTO SelectedRoute (srt_name) VALUES ('" & Value & "')"

A follow up question: Is it possible to do this passing parameters? Something like:

Query = "INSERT INTO SelectedRoute (srt_name) VALUES (?Value)"
 
Upvote 0
Top