2014-02-24 23 views
-2

在此SQL選擇命令中找不到錯誤。數據庫是mySql。選擇命令工作得很好用MS ACCESS數據庫,但:傳遞參數時SQL語句中的錯誤

<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 
+1

嘗試'WHERE(LIKE標題CONCAT( '%',@ IDTextBox1, '%'))',因爲'+'是在MySQL _not_字符串連接。 – Wrikken

回答

0

試試這個沒有額外的引號和+。

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

謝謝!正確的命令是 SelectCommand =「SELECT IDrecipe,title FROM recipe WHERE title LIKE'%'@ IDTextBox1'%'」> – Gloria

+0

@Gloria ok更新了我的答案。很高興你找到解決方案:)。 –

0

您不能在mysql中使用+運算符來將字符串串在一起;使用CONCAT():

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