locked
"query =" produces "query contains" RRS feed

  • Question

  • When I double-click one of my tables and add a query, the choice of relationships includes both "=" and "contains." I am choosing "=."

    However, when I run my query, I'm definitely getting "contains."

     

    Specifically, I search for "ü" and even though there is no entry with only that single character, I'm getting back ALL of the records where the search field contains "ü" such as

    jü3 and bün4 and so on.

     

    My data base server is SQL 2008 R2 running on Windows 7.


    Jim Kay
    Saturday, August 13, 2011 12:52 PM

Answers

  • Actually, all you need to do is make the query parameter optional. What this will do is if the query is passed null for the value of the parameter, any expression that contains that parameter will be ignored.

    To make a query parameter optional:

    • Open the query in the Query Designer
    • Select the parameter so that it is highlighted
    • In the property sheet, check the Is Optional property

    If you run your application now, leaving the Text Box blank will set the parameter to be empty and thus ignored so that your query returns all results.


    Justin Anderson, LightSwitch Development Team
    • Marked as answer by Jim0607 Sunday, August 14, 2011 12:54 PM
    Sunday, August 14, 2011 8:20 AM
    Moderator
  • Let me be more specific:

    I can, I think, create what you described. I get a screen that shows nothing and if I enter a valid code, that appears.

     

    BUT if I want to scroll the entire table, I haven't figured that out yet. (Other than to use the screen I created the first time around.)

     

    I suppose I need some kind of 'wild-card character.'  Is there any such? (A regular expression would do the job very well.)


    Thanks,


    Jim Kay
    • Marked as answer by Jim0607 Sunday, August 14, 2011 12:54 PM
    Sunday, August 14, 2011 5:54 AM

All replies

  • Can you explain the situation a little more? I cannot reproduce the behavior you are seeing.

    When I create a query where one of the properties is filtered to equal "ü":

    It works for me at runtime:

    The left grid is all people and the right grid is based on the query above.


    Justin Anderson, LightSwitch Development Team
    Sunday, August 14, 2011 2:48 AM
    Moderator
  • (I'll have to make two replies because I have three images.)

    Here is the query design:

     

    Here is the initial screen. When the app starts, I choose "Find My Pinyin" from the navigation list.

     

    (cont)


    Jim Kay
    Sunday, August 14, 2011 4:06 AM
  • And, finally, here is what the search produces:

     

    NONE of my data is only "ü" but a number of records contain it.

    One obvious difference is that I'm using a 'parameter' query and you are using a 'fixed' query. Maybe that's the critical difference.


    Jim Kay
    Sunday, August 14, 2011 4:07 AM
  • The search text box of the data grid only filters the data of the collection that the data grid is bound to using containment. If you want to perform some other kind of behavior, such as equality or starts with, then you'll have to create a custom query (just like you did), make it the source of the data grid, and add a screen member to the screen which will be the source of the query parameter.

    Please look at Beth's Creating a Custom Search Screen in Visual Studio LightSwitch blog post for more details.


    Justin Anderson, LightSwitch Development Team
    Sunday, August 14, 2011 4:42 AM
    Moderator
  • Well, I think I follow your meaning but these two steps are not exactly obvious to me at this point:

     

    1. make it the source of the data grid

    2, add a screen member to the screen which will be the source of the query parameter

    Could you please elaborate just a little more?

    Thanks,


    Jim Kay
    Sunday, August 14, 2011 5:39 AM
  • Let me be more specific:

    I can, I think, create what you described. I get a screen that shows nothing and if I enter a valid code, that appears.

     

    BUT if I want to scroll the entire table, I haven't figured that out yet. (Other than to use the screen I created the first time around.)

     

    I suppose I need some kind of 'wild-card character.'  Is there any such? (A regular expression would do the job very well.)


    Thanks,


    Jim Kay
    • Marked as answer by Jim0607 Sunday, August 14, 2011 12:54 PM
    Sunday, August 14, 2011 5:54 AM
  • Actually, all you need to do is make the query parameter optional. What this will do is if the query is passed null for the value of the parameter, any expression that contains that parameter will be ignored.

    To make a query parameter optional:

    • Open the query in the Query Designer
    • Select the parameter so that it is highlighted
    • In the property sheet, check the Is Optional property

    If you run your application now, leaving the Text Box blank will set the parameter to be empty and thus ignored so that your query returns all results.


    Justin Anderson, LightSwitch Development Team
    • Marked as answer by Jim0607 Sunday, August 14, 2011 12:54 PM
    Sunday, August 14, 2011 8:20 AM
    Moderator
  • That did it!

    Thank you,
    Jim


    Jim Kay
    Sunday, August 14, 2011 12:54 PM