Step 2 of 3: Adding a Database and Web Service

In this step you'll add a database to your project, and begin the process of binding the grid. Note that in this step you'll be using the standard Northwind database and an example code file, both of which should be installed with the Studio for Silverlight samples.

To set up your project, complete the following steps:

1.   In the Solution Explorer, expand the .Web project (for example ComponentOneDataGrid.Web) and if the App_Data folder is not visible, right click the .Web project, and select Add | New Folder. Name the folder "App_Data".

2.   In the Solution Explorer, right click the App_Data node, and select Add | Existing Item.

3.   In the Add Existing Item dialog box, navigate to the ComponentOne Samples\Studio for Silverlight\C1.Silverlight.DataGrid\C1DataGrid_MDSL\C1_MDSLWeb\App_Data directory within the Documents or My Documents folder, select the NWIND.mdb file, and click Add to add it to your project.

4.   In the Solution Explorer, select the NWIND.MDB file you just added, and in the Properties window set its Build Action property to None

5.   In the Solution Explorer, right-click the .Web project (for example ComponentOneDataGrid.Web) and select Add | Existing Item.

6.   In the Add Existing Item dialog box, navigate to the ComponentOne Samples\Studio for Silverlight\C1.Silverlight.DataGrid\C1DataGrid_MDSL\C1_MDSLWeb directory within the Documents or My Documents folder, select the SmartDataSet.cs file, and click Add to add it to your project.

Note that for Visual Basic projects, you can find the SmartDataSet.vb file posted online in the forums. This file contains code allowing data transfer to and from the database.

7.   In the Solution Explorer, right-click the .Web project and select Add | New Item.

8.   In the left pane of the Add New Item dialog box, select the Web item.

9.   In the templates list, select Web Service, name the Web Service "DataService.asmx", and click the Add button. Note that the Web Service file will be added to your project and automatically opened.

10.  In the DataService.asmx file, add the following using statements at the top of the file:

      Visual Basic

      C#

11.  Next, uncomment the [System.Web.Script.Services.ScriptService] or <System.Web.Script.Services.ScriptService()> line.

This will allow the Web Service to be called from script.

12.  Delete the existing HelloWorld method and replace it with the following code:

      Visual Basic

      C#

This code will create a dataset and take data from the database.

13.  Right-click the .Web project (for example ComponentOneDataGrid.Web) and select Build from the context menu. Note that you'll now be done with the ComponentOneDataGrid.Web project and will return to working with the ComponentOneDataGrid project.

 What You've Accomplished

In this step you've added a database to your project and created a Web Service. In the next step you'll finish connecting the Web Service to your project and you'll run your application.


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.