Android Question sqlite populate spinner and update spinner, possible?

fifiddu70

Well-Known Member
Licensed User
hello, i use sqlite for populate spinner for my project, i need to update the element stored in database, for populate i use this code:
B4X:
dbSQL.ExecNonQuery2("INSERT INTO field9 VALUES (?)", Array As String(txtmenu.Text & " - " & "Euro" & " " & txtcaricoeuro.Text))
            spmn9.Add (txtmenu.Text & " " & "Euro" & " " & txtcaricoeuro.Text)
            txtcaricoeuro.Text=""
            dbCursor.Close
            txtmenu.Text=""
example in txtmenu i write: Spaghetti and txtcaricoeuro i write: 6.00
with spmn9.add i added: spaghetti - Euro 6.00
with thi code i load the spinner with all data stored:

B4X:
Sub mn9
    
    spmn9.Clear
    dbCursor = dbSQL.ExecQuery("SELECT * FROM field9")
    For I = 0 To dbCursor.RowCount - 1
        dbCursor.Position = I
        spmn9.Add(dbCursor.GetString("data9"))
       Next
    dbCursor.Close
End Sub
Now i need to modify one element loaded in this spinner.
example: Spaghetti - euro 6.00 updated with Spaghetti - Euro 7.50

what code should i use to modify this element?

for delete element i use:
B4X:
dbSQL.ExecNonQuery2("DELETE FROM field9 WHERE data9 = ?", Array As String(spmn9.SelectedItem))
for update or modify this element without delete?
 

fifiddu70

Well-Known Member
Licensed User
Erel
it's an old method I learned from a member and I've always worked like that. anyway thanks for your advice.
 

fifiddu70

Well-Known Member
Licensed User
Looks a bit strange that you are not using two columns. One for the product and one for the price.
B4X:
dbSQL.ExecNonQuery2("UPDATE field9 SET data9 = ? WHERE data9 = ?", Array As String("Spaghetti - Euro 7.50",spmn9.SelectedItem))
Erel, excuse me, but now there is another problem, there are 9 spinner renamed as: spmn1 - spmn2 - etc. so how do I update an item in one of these spinners?
 
Top