So I have got an ArrayList called arr, which contains strings such as “decoration”, “metal”, “paper” etc.
What I want to do is loop though that ArrayList, adding each tag to a query string with which to get data from a database.
Currently I have something like this:
String strSel="select * from Table1 where Tags";
for(int x=0;x<arr.Count;x++){
if (x == arr.Count - 1)
{
strSel += " like '%'"+arr[x]+"'%'";
}
else
{
strSel += " like '%'" + arr[x] + "'%' or Tags";
}
}
cmdSel=new SqlCommand(strSel,connectionName);
sqlDataReaderName=cmdSel.ExecuteReader();
Anyway I get an error about “Incorrect syntax near bla”…its has probably got something to do with the single quotes or wildcards but I can’t figure it out. What am I doing wrong?
you should remove extra single quote before and after the
percent symbolthe reason why error has been thrown is because your query is formed like this