Articles → Light Switch 2011 → Queries In Light Switch 2011

Queries In Light Switch 2011






Software Requirement




  1. Visual studio 2010 is installed on your machine.
  2. Visual Studio 2010 service pack 1 is installed on your machine.
  3. Microsoft Visual Studio Light switch 2011 is installed on your machine.
  4. Silverlight runtime version 4 or 5 is installed on your machine

Prerequisite Knowledge




  1. How to create project using visual studio?
  2. How to create screens in lightswitch?
  3. How to create tables in lightswitch?

What Is A Query?





Steps Of Execution




  1. Create a new project
  2. Create a new table
  3. Add data in the table
  4. Add query on the table
  5. Add parameters in query
  6. Bind grid with query
  7. Bind drop down with query



Create A New Project




Picture showing the project structure of the lightswitch application
Click to Enlarge


Create A New Table




Picture showing the schema of the student table in the lightswitch table designer
Click to Enlarge


Add Data In The Table




Picture showing the editable grid screen with data
Click to Enlarge


Add Query On The Table




  1. Right click on the table and click on Add Query.
  2. Picture showing the add query option in the context menu of the table
    Click to Enlarge

  3. A designer screen will open and a new query Query1 will be created. You can rename the query by double click on it
  4. Picture showing the new query added in the solution explorer
    Click to Enlarge





Add Parameters In Query




  1. Click on Add Filter option
  2. A new row will be added from which you can add where condition for the query.
  3. Picture showing the button for adding the filters in the query
    Click to Enlarge




  1. In the first column we have a drop down having 2 values i.e. where and where not.
  2. Second column contains the list of all fields in a table on which filter can be applied. You can select any of the field.
  3. Third column is a drop down which contains the list of comparison operators like equal to, not equal to and so on.
  4. Fourth column is for the type of query parameter. It can be a literal i.e. hard coded string, a property or a parameter which can be set at run time.
  5. Fifth column is the value of query parameter.
  6. Picture showing the filters added in the query
    Click to Enlarge




Picture showing adding the value to the filters
Click to Enlarge



Picture showing the filters added in the query
Click to Enlarge





  1. Click on the parameter and press F4
  2. Property window will be opened on the right hand side.
  3. Check the option ‘Is Optional’
  4. Picture showing marking the parameter as optional in the query
    Click to Enlarge



Bind Grid With Query




  1. First of all add a new screen of type Editable grid screen.
  2. Select query as data source of the screen. See the screen shot below
  3. Picture showing creating the new Editable Grid screen with query as data source
    Click to Enlarge

  4. Click Ok


Picture showing creating a new data field to be used as query parameter
Click to Enlarge



Picture showing the data in the grid bound with the query
Click to Enlarge


Bind Drop Down With Query






Picture showing adding the new data item in the project
Click to Enlarge





Picture showing selecting the the query as data source of the data item
Click to Enlarge



Picture showing the query parameter data source in the property window
Click to Enlarge




Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, August 6, 2013

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250