Last post Mar 28, 2011 02:19 PM by TheDirtyBird
Mar 28, 2011 12:41 PM|TheDirtyBird|LINK
How can I get my sqldatasource to recognize the LIKE wildcard? My query needs to be like this:
WHERE (submitter LIKE '%g%')
That will return results that has the letter g even if the word starts with g.
My sqldatasource passes in a parameter but I don't now how to format my query:
<asp:SqlDataSource ID="SqlDataSourceCCBName" runat="server"
ConnectionString="<%$ ConnectionStrings:CCBcs %>"
WHERE (CCBName LIKE '%' + @CCBName +'%')">
Mar 28, 2011 12:46 PM|limno|LINK
Your code looks good.
SelectCommand="SELECT * FROM vwUsers WHERE (CCBName LIKE '%' + @CCBName +'%') "
Mar 28, 2011 12:51 PM|TheDirtyBird|LINK
I built a search. With my datasource the way it is now, it will not find the first letter. For example, if the user puts the letter g in the textbox and clicks submit, it will not find words such as good, girl, great.
Mar 28, 2011 12:55 PM|limno|LINK
What data type is CCBName? Make it varchar(1000) and try again.
Mar 28, 2011 12:58 PM|TheDirtyBird|LINK
Changing the datatype to varchar fixed my search. I had nvarchar. Wonder why it doesn't recognize it with nvarchar?
Thanks for your help!
Mar 28, 2011 02:11 PM|limno|LINK
You can try to put N in front of your first wildcard to make it work:
SELECT * FROM @t WHERE (CCBName LIKE N'%' + @CCBName +'%')
Mar 28, 2011 02:19 PM|TheDirtyBird|LINK
I just changed the datatype to VarChar. Again, thanks for your help.