0

Where="((ProgModelID == @ProgModelID) || (@ProgModelID == @ShowAll)) && (((FirstName + ' ' + MiddleName + ' ' + LastName) LIKE '%' + @Name + '%') || ((FirstName + ' ' + LastName) LIKE '%' + @Name + '%'))"

I need to concatenate the full name together when comparing against a TextBox in order to filter a GridView, but this error comes up when I try to run it. The error changes to Expression expected when I place [] around each FirstName, MiddleName and LastName.

Update

I have a textbox which a user can type a name into to filter a GridView's results. the GridView has a LinqDataSource. The problem is the name is divided in the database into 3 parts: first, middle, last. I want to be able to filter by first+last name, as well as first+middle+last name. The areas related to ProgModel are for a DropDownList and already function if the sections related to @Name are removed.

Filip
  • 3,257
  • 2
  • 22
  • 38
Jenius
  • 174
  • 15

2 Answers2

1

I figured out how to avoid this error, and a probable cause for it. I added computed columns to the view the LinqDataSource was pulling rows from for FullName (first, middle, last) and Name (first, last).

I then changed LIKE to .Contains() and received a no applicable method 'contains' exists in type 'string' error. What happened was I forgot to add ConvertEmptyStringToNull="false" to the ControlParameter for the TextBox (I found out this solution from the link here). That managed to fix everything.

Jenius
  • 174
  • 15
0

You need just one more ) at the end is all..This will complete the wrap after your &&

Try this:

Where="((ProgModelID == @ProgModelID) || (@ProgModelID == @ShowAll)) && 
(((FirstName + ' ' + MiddleName + ' ' + LastName) LIKE '%' + @Name + '%') 
|| ((FirstName + ' ' + LastName) LIKE '%' + @Name + '%')))"

Or - to make it a little easier to read and still get the same result, remove one of the ( before FirstName + ' ' - like:

Where="((ProgModelID == @ProgModelID) || (@ProgModelID == @ShowAll)) && 
((FirstName + ' ' + MiddleName + ' ' + LastName) LIKE '%' + @Name + '%') 
|| ((FirstName + ' ' + LastName) LIKE '%' + @Name + '%'))"

Ultimately the error message says it all :)

Darren Wainwright
  • 30,247
  • 21
  • 76
  • 127
  • I still receive the same error. But thanks for noticing the extra parenthesis. Am I not allowed to concatenate strings **before** a `LIKE`? – Jenius Jul 15 '13 at 19:40
  • 1
    It's looking super complex - the way you're trying to achieve your goal - perhaps update your question with what you're actually trying to do, might be some much better ways to handle it.. – Darren Wainwright Jul 15 '13 at 19:45