Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Proper way to use LIKE operator with SqlDataSource and control parameters in declarative markup?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kenfine@nospam.nospam - 18 Aug 2007 01:35 GMT
I'm trying to use LIKE operators in SqlDataSource with Control Parameters.
The following should express my intent, but it does not work in the way I
want it to (returns no results):

SelectCommand="SELECT title, conid FROM Contentitems WHERE ((categoryid =
'102') AND (byline LIKE '%@byline%')) OR ((categoryid = '102') AND (keywords
LIKE '%@keywords%')) OR ((categoryid = '102') AND (keywords LIKE
'%@jobid%'))  OR ((categoryid = '102') AND (title LIKE '%@keywords%'))">

Besides generating the string that should go with the SelectCommand
programmatically, is there a way to make this work right declaratively?

Subbing in literal values returns a whole lot of results:

SelectCommand="SELECT title, conid FROM Contentitems WHERE ((categoryid =
'102') AND (byline LIKE '%president%')) OR ((categoryid = '102') AND
(keywords LIKE '%president%')) OR ((categoryid = '102') AND (jobid LIKE
'%president%'))  OR ((categoryid = '102') AND (title LIKE '%president%'))">

Help out there? MSDN managed newsgroup support should be linked to this
account in, oh, 12 hours or so. :)

Thanks!

-KF
kenfine@nospam.nospam - 18 Aug 2007 01:45 GMT
Yeah, I know that that first SQL statement seemed a little funny, but the
"corrected" version doesn't help either:

SelectCommand="SELECT title, conid  FROM Contentitems WHERE ((categoryid =
'102') AND (byline LIKE '%@byline%')) OR ((categoryid = '102') AND (keywords
LIKE '%@keywords%')) OR ((categoryid = '102') AND (jobid LIKE '%@jobid%'))
OR ((categoryid = '102') AND (title LIKE '%@title%'))">

> I'm trying to use LIKE operators in SqlDataSource with Control Parameters.
> The following should express my intent, but it does not work in the way I
[quoted text clipped - 22 lines]
>
> -KF
kenfine@nospam.nospam - 18 Aug 2007 03:07 GMT
This CAN be done from declarative code.

The answer is to use concatenation operators and single quotes around the
percent symbols as follows:

SelectCommand="SELECT title, conid FROM Contentitems WHERE ((categoryid =
'102') AND (byline LIKE '%' + @byline + '%')) OR ((categoryid = '102') AND
(keywords LIKE '%' + @keywords + '%')) OR ((categoryid = '102') AND (jobid
LIKE '%' + @jobid + '%'))  OR ((categoryid = '102') AND (title LIKE '%' +
@title + '%'))">

> Yeah, I know that that first SQL statement seemed a little funny, but the
> "corrected" version doesn't help either:
[quoted text clipped - 31 lines]
>>
>> -KF

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.