Articles → LIGHT SWITCH 2011 → Bind Grid With View In Lightswitch 2011

Bind Grid With View In Lightswitch 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.

Prerequisite Knowledge




  1. How to create lightswitch project?
  2. How to create an entity in lightswitch?
  3. How to create a screen in lightswitch?
  4. Basics about objects like tables, views etc in SQL server

Steps For Execution




  1. Create a new lightswitch project
  2. Create tables
  3. Adding data in the tables
  4. Add data source in lightswitch
  5. Add new screen from table
  6. Add view in the database.
  7. Update data source.
  8. Add new screen from view



Create A New Lightswitch Project




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


Create Tables




Picture showing the schema of the Employee table
Click to Enlarge

Picture showing the schema of the Department table
Click to Enlarge


Adding Data In The Tables




Picture showing the data in the Employee table
Click to Enlarge

Picture showing the data in the Department table
Click to Enlarge


Add Data Source In Lightswitch




Picture showing the context menu with the Add Data Source option
Click to Enlarge



Picture showing the Add data source wizard to select the datasource type
Click to Enlarge



Picture showing setting up the connection string for SQL server database
Click to Enlarge



  1. Enter server name
  2. Select authentication type i.e. windows authentication or SQL Server authentication.
  3. Select database.
  4. Click on ‘Test Connection’ (this step is optional).
  5. Once the connection is tested successfully click on Ok.
Picture showing the list of tables in the database
Click to Enlarge



Picture showing the data source added in the lightswitch project
Click to Enlarge


Add View In The Database




CREATE VIEW vw_GetEmployeeData AS 
SELECT 
  e.EmployeeId, 
  e.EmployeeName, 
  d.DepartmentName 
FROM 
  Employee e 
  INNER JOIN Department d ON e.DepartmentId = d.DepartmentId



Update Data Source






Picture showing the context menu of the data source with update datasource option
Click to Enlarge



Picture showing the update data source wizard for adding the view in the data source
Click to Enlarge



Picture showing the warning message when the view is added in the data source
Click to Enlarge



Picture showing the view added in the data source
Click to Enlarge


Add New Screens




Picture showing adding the Editable Grid Screen in the project
Click to Enlarge



Picture showing the data source and screens added in the project
Click to Enlarge


Output




Picture showing the screen bound with table
Click to Enlarge

Picture showing the screen bound with view
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, November 28, 2012

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250