This article describes binding of a Grid with a View in LightSwitch 2012.
Procedure for binding a grid with a view in LightSwitch.
Step 1
Open the Solution Explorer for the new project as in the following:
Step 2
Now open the SQL Server Management Studio (SSMS).
Right-click on "DataBase" and choose "New DataBase...".
Provide a name for the database and click the "OK" button.
Step 3
For creating a Table in the database, right-click on the table and choose "New Table".
In this way we will create two tables.
Student Table
Subject Table
Now I will add some data in both the tables.
Step 4
In the application, go to the Solution Explorer and choose "Add Data Source".
The Attach Data Source Wizard Dialog Box appears.
Choose "Database" and click the "Next" Button.
In the Connection Properties dialog Box, enter the Server Name then select the Authentication Type, after selecting the server name select the database.
Once all the credentials are entered, click on the "Test Connection" button to test the connection. A dialog box will appear, click the "OK" button.
Once the connection is tested click the "OK" button to proceed further.
Select the DataBase Object that you want to choose, after selecting the objects click "Finish" button.
Step 5
Now you will notice that the DataSource will be added to the Solution Explorer.
Step 6
In order to create a view in the database, right-click on "View" and choose "New View".
The Add Table dialog box appears from which you can select the table that you want to use in order to create a view.
Select the data from the table that you want to use in order to create a view and then save the view and provide a name to the view.
Step 7
Right-click on Data Source and choose "Update Datasource".
The Database Object Dialogbox appears on the screen. Select a view from the Database object and click "Finish" button.
After clicking the "Finish" button, a warning pop-up will appear, click the "Continue" button to update the database.
Step 8
Right-click on Screen and choose "Add Screen".
The Add New Screen dialog box appears. Select the "Editable Data Grid Screen" from the Screen Template, under screen information, choose "Student" under screen data and provide some name to the Screen and click the "OK" button.
In the same way we will add another Editable Grid Screen for the View.
Step 9
Press F5 to run the application.