我正在将变量传递给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。
结果显示在列表视图中,但是什么也没有。
答案 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 & "'")