androidsqlsqlitevb6vb4android

Variable passed to SQL statement returns nothing, no errors though


I'm passing a variable to an SQL query.

Dim accept As String
accept = Cursor1.GetString("accepted_id")
    Msgbox(accept, "")  
    Cursor1 = SQL1.ExecQuery("SELECT answer FROM answers WHERE accepted_id =" & " 'accept' " )

There's more code but that should be enough. There are no errors and the msgbox shows the correct answer. it all looks good but it's not retrieving any results.

If I hardcode the answer instead of the variable it works, such as,

 Dim accept As String
    accept = Cursor1.GetString("accepted_id")
        Msgbox(accept, "")  
        Cursor1 = SQL1.ExecQuery("SELECT answer FROM answers WHERE accepted_id =" & " 'CD6028' " )

The msgbox shows CD6028.

The results show show in a listview but nothing.


Solution

  • It seems like you are passing litteral string accept to the variable instead of variable accept itself.

    Replace this :

    Cursor1 = SQL1.ExecQuery("SELECT answer FROM answers WHERE accepted_id =" & " 'accept' " )
    

    With :

    Cursor1 = SQL1.ExecQuery("SELECT answer FROM answers WHERE accepted_id = '" & accept & "'")