传递给SQL语句的变量不返回任何内容,尽管没有错误

时间:2019-01-21 01:28:31

标签: sql sqlite vb6 vb4android

我正在将变量传递给SQL查询。

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

还有更多代码,但这应该足够了。没有错误,并且msgbox显示正确的答案。一切看起来不错,但是没有检索到任何结果。

如果我对答案进行硬编码而不是对变量进行编码,例如

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

msgbox显示CD6028。

结果显示在列表视图中,但是什么也没有。

1 个答案:

答案 0 :(得分:2)

似乎您正在将垃圾字符串accept传递给变量,而不是变量accept本身。

替换此:

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

使用:

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