Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Tips Database Forum Rss Feed

» Database Journal Home
» Database Articles
» Database Tutorials
MS Access
SQL Scripts & Samples
» Database Forum
» Slideshows
Free Newsletters:

News Via RSS Feed

Rss Feed

Database Journal |DBA Support |SQLCourse |SQLCourse2

Featured Database Articles


Posted Aug 15, 2006

How to Build an ASP.NET Web Site Using DB2 Data with Visual Studio 2005 - Page 3

By Paul Zikopoulos

If you want to have DB2 populate your Web page only with unique rows, you can select the Return only unique rows check box.

11.  Click Advanced. The Advanced SQL Generation window opens.

12.  Select the Generate INSERT, UPDATE, and DELETE statement check box and click OK.

When you select this option, Visual Studio 2005 will automatically generate the supporting SQL data manipulation language (DML) for your DB2 database. Of course, you can do this manually as outlined in the previous step. However, if you're not planning to customize any of the default generated SQL, why not let Visual Studio 2005 handle it for you?

13.  Click Next. The Test Query window opens

14.  Click Test Query to preview the data that will be used to populate your Web page, and click Finish.

15.  From the Toolbox Data section, drag the GridView object (used to represent a data grid) and drop it just below the SqlDataSource object that you added in Step 5, as shown below:

16.  Click the Choose Data Source drop-down list and select SqlDatasource1 (the default name assigned to the SAMPLE database's EMPLOYEE table that you configured in the previous steps).

The data grid should be refreshed and look like this:

You can see that Visual Studio 2005 has started to bind the data columns to the data grid. The data that's displayed in the data grid are just place holders at this point and are used to represent each column's data type.

17.  You can configure some automated usability features that Visual Studio 2005 can automatically add to your Web page by clicking on the toggle at the right-most part of the grid view (if it did not open automatically, or if you closed it). For this example, select the Enable Paging, Enable Sorting, Enable Editing, Enable Deleting, and Enable Selection check boxes, as shown below, and then click anywhere in the data grid to return focus to the designer palette:

The GridViewTasks offers you a lot of options for the way the data is displayed on your Web page. For example, you can override what columns are displayed, their order, and so on, and perform a number of operations such as those shown in the previous figure. When you select any of these options, Visual Studio 2005 automatically adds links for these actions to the data grid – talk about easy!

You can see some of the results of the actions from this step below:

You can see links have been added to perform editing of data, deleting of data, and selecting of the data from your Web page (provided you have these privileges on the tables you are connecting to).

Also note the 1 2 links at the bottom of the data grid. Visual Studio 2005 attached these to your data grid because you selected the Enable paging option, which has the effect of breaking down large result sets into multiple pages and providing these controls to page through your query.

18.  In the same manner in which you dragged the DataGridView object to your designer palette, place a DetailsView object (also located in the Data section of the Toolbox) just below the DataGridView. The designer palette should now look like this:

19.  Click Choose Data Source and select the SqlDataSource1 object.

As you bound your DB2 data to your data grid, you also have to bind the details of a selected row to this control object as well.

20.  Ensure that the options for this object match the following figure:

You can see the designer palette will bind a row to the details view and provide you with similar options as it did in Step 17. Once again, if you look at the bottom of the previous figure, you can see Visual Studio 2005 is adding controls to the Web page automatically for you.

21.  Press Ctrl+F5 to see your Web site!

One of the great new features in Visual Studio 2005 is an integrated application server hosting environment (based on IIS) that allows you to quickly and easily test your Web applications. I love this feature and DB2 can take advantage of it.

If you scroll to the bottom of your Web page, you should see the controls added by Visual Studio 2005:

22.  Play around with the different links that were generated because of the options you selected for the data grids. When you're finished, close the Web page, and stop the application server, as shown below:

DB2 Archives