Gab Gab - 20 days ago 5
MySQL Question

I'm having an error in mysql like commmand ="SELECT * FROM subjects WHERE Course LIKE ('%'+ ? + '%')

I want to have a search function in my system so I use textbox and button to display data in gridview.

But I don't know what is the right syntax to use like command. This syntax doesn't show any data in gridview.

"SELECT * FROM subjects WHERE Course LIKE ('%'+ ? + '%')"


I'm using sql data source on gridview. Thanks

Answer

In mysql you don't have + for string concatenation

so you should use concat (assuming you pass a param for ?)

"SELECT * FROM subjects WHERE Course LIKE CONCAT('%', ? , '%');"

or procedural code

 "SELECT * FROM subjects WHERE Course LIKE '%'" + SomeText+ "%';"

or like suggested by vbnet3d for VB.Net

"SELECT * FROM subjects WHERE Course LIKE '%" & SomeText & "%'"