Database Support Video Highlights

  • Preparing to make a data-driven Web page editable
  • Using a DataGrid or GridView to allow editing data in a database
  • Creating SQL statements to reference data
  • Creating data-driven applications entirely on the design surface

Evaluate Visual Studio

Introduction

Welcome to this product comparison video overview showing the differences between the latest Web design tools available from Microsoft and Macromedia, namely, Microsoft’s Visual Studio 2005 and Macromedia’s Dreamweaver, Version 8. The goal of most Web sites is to provide relevant data for users. Often, this data is housed in a database and needs to be referenced in a reliable and secure fashion. In this video, we will examine the ways Dreamweaver Version 8 and Visual Studio 2005 can create Web pages that present data to users.

Dreamweaver Section

Dreamweaver supports the use of the DataSet and data-bound controls from ASP.NET Version 1.1, but has no current support for the data source from ASP.NET Version 2.0 or additional data access methods which simplify working with data. A previous video in the series showed how Dreamweaver can use a DataSet and a DataGrid to present data. We will build on that starting point in this video to allow updating individual records found in the database. With this simple DataSet and DataGrid, information from the employees table is presented when the Web page is rendered. To present information from a selected row in a database, we need to get a key value to know what specific row should be updated. So we’ll first modify the DataSet to include the EmployeeID column… as well, we’ll need to update the DataGrid to have this EmployeeID column and also a special column to allow editing. Clicking the +/plus column on the Columns list allows you to add a column of your choosing. First, we will add the special ‘Edit, update, and cancel buttons’ column. And now to facilitate updating the right records in the database, we will add a Simple Data Field Column for EmployeeID. We can set the ‘Read only’ property of the EmployeeID column so that it is not updated with the row. We now need to go into each of the other three columns and turn off the ‘Read only’ setting. By default, this is enabled, but it must be turned off for the columns where we want the editing text box to appear. Although the EmployeeID column is necessary to be included in the grid, we don’t actually want the ID value to be shown on the page, so going back to the code, note what has been added is this ASP BoundColumn tag. Using the Tag Editor, it is possible to turn off the visibility for this specific column. Another section of that was added when we modified the column list on the DataGrid is this special EditOps section that’s a part of the DataSet. It must represent the columns to be edited in the proper order except for columns that are not updated such as this EmployeeID column that then should be placed at the end of the list. The special Macromedia PageBind control defaults to having the PostBackBind attribute set true. This has worked our fine so far for our examples, but now we will need to set this to false in order for the change data being posted back by the user to not be overwritten before the update occurs on the database. Now the solution can be tested to ensure that it properly updates records in the database. As an example, let’s say that Margret Peacock was just married and her last name and address need to be changed. Using the Edit link, the fields for that record are rendered as text boxes… and then the changes can be made.

Visual Studio 2005 Section

Data access in Visual Studio 2005 is simplified with new features introduced by the .NET Version 2 Framework. ASP.NET Version 2 eliminates much of the extra code with the introduction of new set of objects that works specifically with data access and retrieval. These new controls can be configured entirely around the design surface, allowing the developer to create solutions without writing any code. In a previous video, we had used this SqlDataSource to populate sample employee information in a GridView control. In addition the SqlDataSource server control, Visual Studio 2005 introduced the ‘AccessDaraSource,’ ‘Object DataSource,’ ‘XmlDataSource,’ and ‘SiteMapDataSource’ server controls. These new controls provide a declarative way to connect to server controls and retrieve specific data. Visual Studio 2005 also provides new data-bound server controls that can be used in conjunction with new data source controls to display retrieve data in the browser. The previous video demonstrated use of the GridView control to present data. In this video, we will work from that starting point and add the same kind of editing capabilities we had done in Dreamweaver, providing update features. When we had configures the SqlDataSource object previously, we had only established the select query. Now, referencing the Query Builder, we will need to add the EmployeeID column to the Select Query Property. This obtains the primary key value from the table. In order for updates to take place, the DataGrid needs to have a reference to know which column holds the IDs, which is stored in the DataKeyNames property. So in this case, EmployeeID is entered. Now working with the update statement, let’s examine the Query Builder which allows us to choose the Employees table and select the columns we would like to act upon. We will choose the same three we have worked with so far, FirstName, LastName, and Address. The SQL statement shown is automatically generated based on our choices. We need to add parameters to each of the three columns we’re updating… and add an appropriate where clause to limit the update to affect the specific row based on the EmployeeID… and with that, we have a valid SQL statement we can use for update. To put the parameters in place, it is important to select ‘Refresh Parameters.’ To cause the GridView to use the new statement we added to the SqlDataSource, from its Properties window, we can simply set AutoGenerateEditButton to ‘True.’ All of the functionality to make the data editable is then automatically established. The newly introduced data-bound controls are simple to configure to enable data access through a data source. Running our page, we’ll find the ability to easily edit our Employees table. Click the Edit button, and our edit fields change to text boxes and our Edit button changes to the Update/Cancel set of buttons. In Visual Studio 2005, we were able to establish this kind of activity and edit functionality entirely from the design surface of the ASP.NET Web form.

Conclusion

This concludes our comparison of Dreamweaver Version 8 and Visual Studio 2005 regarding data source and data-bound controls.