Answered by:
Sqldatasource and LIKE command

Question
-
User324972980 posted
How can I get my sqldatasource to recognize the LIKE wildcard? My query needs to be like this:
SELECT * FROM vwUsers 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 %>" SelectCommand="SELECT * FROM vwUsers WHERE (CCBName LIKE '%' + @CCBName +'%')">
Monday, March 28, 2011 12:41 PM
Answers
-
User77042963 posted
What data type is CCBName? Make it varchar(1000) and try again.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, March 28, 2011 12:55 PM
All replies
-
User77042963 posted
Your code looks good.
SelectCommand="SELECT * FROM vwUsers WHERE (CCBName LIKE '%' + @CCBName +'%') "
Monday, March 28, 2011 12:46 PM -
User324972980 posted
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.
Monday, March 28, 2011 12:51 PM -
User77042963 posted
What data type is CCBName? Make it varchar(1000) and try again.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, March 28, 2011 12:55 PM -
User324972980 posted
Changing the datatype to varchar fixed my search. I had nvarchar. Wonder why it doesn't recognize it with nvarchar?
Thanks for your help!
Monday, March 28, 2011 12:58 PM -
User77042963 posted
You can try to put N in front of your first wildcard to make it work:
SELECT * FROM @t WHERE (CCBName LIKE N'%' + @CCBName +'%')
Monday, March 28, 2011 2:11 PM -
User324972980 posted
I just changed the datatype to VarChar. Again, thanks for your help.
Monday, March 28, 2011 2:19 PM