Case Study: Connecting to a Database in ASP.NET
Many websites allow users to provide feedback about the website in a guestbook. Typical-ly, users click a link on the website’s home page to request the guestbook page. This page usually consists of an XHTML form that contains fields for the user’s name, e-mail ad-dress, message/feedback and so on. Data submitted on the guestbook form is then stored in a database located on the web server’s machine.
In this section, we create a guestbook Web Form application. This example’s GUI is slightly more complex than that of earlier examples. It contains a GridView ASP.NET data control, as shown in Fig. 25.30, which displays all the entries in the guestbook in tabular format. We explain how to create and configure this data control shortly. Note that the GridView displays abc in Design mode to indicate string data that will be retrieved from a data source at runtime.
The XHTML form presented to the user consists of a name field, an e-mail address field and a message field. The form also contains a Submit button to send the data to the server and a Clear button to reset each of the fields on the form. The application stores the guestbook information in a SQL Server database called Guestbook.mdf located on the web server. (We provide this database in the examples directory for this chapter. You can download the examples from www.deitel.com/books/iw3htp4.) Below the XHTML form, the GridView displays the data (i.e., guestbook entries) in the database’s Messages table.
Copyright © 2018-2020 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.