Using LIKE query operator in v2.0

Posts   
 
    
larkydoo
User
Posts: 45
Joined: 30-Jun-2008
# Posted on: 06-Aug-2008 16:01:32   

I'm having a hard time figuring out how to use the LIKE operator in LLBLGEN. Suppose I have a SELECT statement like the following:

SELECT * FROM Events WHERE EventDescription like '%Tuesday%'

How would this look in self-servicing code?

Thanks much.

Laurie

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 06-Aug-2008 16:11:16   

The filter should look like the following:

PredicateExpression filter = new PredicateExpression();
filter.Add(EventsFields.EventDescription % "%Tuesday%");
larkydoo
User
Posts: 45
Joined: 30-Jun-2008
# Posted on: 13-Aug-2008 18:45:30   

Okay, then how would it look if the keyword you were searching for were a variable, e.g. instead of the word "Tuesday" you had the string strDayOfWeek?

Micah
User
Posts: 11
Joined: 26-Jun-2007
# Posted on: 13-Aug-2008 19:02:43   

larkydoo wrote:

Okay, then how would it look if the keyword you were searching for were a variable, e.g. instead of the word "Tuesday" you had the string strDayOfWeek?


'in VB
Dim pe as New PredicateExpression()
Dim search as String = "%" & strDayOfWeek & "%"
'.NET 2.0
pe.Add(EventsFields.EventDescription Mod search)
'alternately
pe.Add( New FieldLikePredicate(EventsFields.EventDescription, search))

hope this helps

-Micah

larkydoo
User
Posts: 45
Joined: 30-Jun-2008
# Posted on: 13-Aug-2008 19:42:10   

Works great! Thanks! smile