传递参数时SQL语句出错

时间:2014-02-24 18:48:13

标签: mysql sql

在此SQL select命令中找不到错误。数据库是mySql。 select命令与MS ACCESS数据库完美配合,但是:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:recipesConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:recipesConnectionString.ProviderName %>" 
        SelectCommand="SELECT IDrecipe, title FROM recipe WHERE (title LIKE '%' + @IDTextBox1 + '%')">

    </asp:SqlDataSource>

以上会产生以下错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '+ 'sauce' + '%')' at line 1 

2 个答案:

答案 0 :(得分:0)

尝试此操作时不需要额外的引号和+。

 SelectCommand="SELECT IDrecipe, title 
                FROM recipe 
                WHERE title LIKE '%' @IDTextBox1 '%' ">

答案 1 :(得分:0)

你不能在mysql中使用+运算符来阻塞字符串;使用CONCAT():

SelectCommand="SELECT IDrecipe, title FROM recipe WHERE (title LIKE CONCAT('%', @IDTextBox1, '%') )">