简体   繁体   English

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

[英]Variable passed to SQL statement returns nothing, no errors though

I'm passing a variable to an SQL query. 我正在将变量传递给SQL查询。

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. 没有错误,并且msgbox显示正确的答案。 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. msgbox显示CD6028。

The results show show in a listview but nothing. 结果显示在列表视图中显示,但没有显示。

It seems like you are passing litteral string accept to the variable instead of variable accept itself. 似乎您正在将垃圾字符串accept传递给变量,而不是变量accept本身。

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 & "'")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM