34
Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 12 1 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 12 Accessing Databases from Web Applications with Microsoft ASP.NET Part A Raymond Frost – John Day – Craig Van Slyke

DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

  • Upload
    alaina

  • View
    18

  • Download
    0

Embed Size (px)

DESCRIPTION

DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH. Raymond Frost – John Day – Craig Van Slyke. Chapter 12 Accessing Databases from Web Applications with Microsoft ASP.NET Part A. Active Server Page Model. Exhibit 12-1: The Basic Active Server Page Model. Files for a Web Application. - PowerPoint PPT Presentation

Citation preview

Page 1: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

1

DATABASE DESIGN AND DEVELOPMENT: A VISUAL

APPROACH

Chapter 12Accessing Databases from Web

Applications with Microsoft ASP.NETPart A

Raymond Frost – John Day – Craig Van Slyke

Page 2: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

2

Active Server Page Model

Exhibit 12-1: The Basic Active Server PageModel

Page 3: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

3

Files for a Web Application

Exhibit 12-2: The Active Server Page FileStructure

Page 4: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

4

An Example Web Application

Exhibit 12-3: A Simple Web Page

Page 5: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

5

Web Developer Environment

Exhibit 12-4: The Web Developer DevelopmentEnvironment

Page 6: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

6

Creating a New Web Site

Exhibit 12-5: The New Web Site Dialog Box

Page 7: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

7

Source View

Exhibit 12-6: The Initial Display After Creatingthe Application

Page 8: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

8

Design View

Exhibit 12-7: The Simple Web Application inDesign View

Page 9: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

9

The Toolbar

Exhibit 12-8: Displaying the Toolbox

Drag a Button and a Label Control onto the design

Page 10: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

10

The Completed Design

Exhibit 12-9: The Design for the Simple WebApplication

Page 11: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

11

Button Control Properties

Exhibit 12-10: The Properties for the Button

The Text property will be changed to “Time” so that text will be displayed on the button.

Page 12: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

12

Programming the Button

Exhibit 12-11: The Code for the Button ClickEvent

Double-click the button to display the event code associated with the button.

Page 13: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

13

Intellisense

Exhibit 12-12: Using Intellisense to Enter Code

Once you type part of the code and reach a period, the drop-down list with available options will be displayed.

Label1.Text = DateTime.Now

Page 14: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

14

Testing the Application

Exhibit 12-13: The Results of the Simple WebApplication

When the Time button is clicked, the label will display the current time.

Page 15: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

15

The Application to Display a Table

Exhibit 12-14: The Application to Display theMEMBER Table

Page 16: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

16

SqlDataSource Control

Exhibit 12-15: Adding the SqlDataSource Control to the Project

Drag a copy of the SqlDataSource control to connect the application to a database.

Page 17: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

17

Common Tasks

Exhibit 12-16: Common Tasks for the SqlDataSource Control

When you click on the arrow in the upper right corner of the control, the common tasks for that control will be shown.

In this case, the next task is to configure the data source.

Page 18: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

18

Configure Data Source Wizard

Exhibit 12-17: Adding the SqlDataSourceControl to the Project

First, create a new connection.

Page 19: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

19Exhibit 12-18: Other Data Sources Availablefor the SqlDataSource Control

Configure Data Source Wizard

Select the type of data source: in this case, Microsoft SQL Server.

Page 20: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

20Exhibit 12-19: The Add Connection Dialog Box

Configure Data Source Wizard

For an SQL Server Data Source, select the server: Localhost is for a testing the application against a local copy of SQL Server.

Enter the user name and password to gain access to the database.

Select the database.

Page 21: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

21Exhibit 12-20: Finishing the Selection of a Connection

Configure Data Source Wizard

The newly created connection will be used so just click Next>.

Page 22: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

22Exhibit 12-21: Saving the Connection

Configure Data Source Wizard

Saving the connection will depend on whether your environment allows the use of a web.config file. If not, you can skip this step.

Page 23: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

23Exhibit 12-22: Finishing the Selection of aConnection

Configure Data Source Wizard

A select statement is constructed to retrieve the needed data.

Page 24: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

24Exhibit 12-23: Testing the Query

Configure Data Source Wizard

The select statement can be tested to make sure it is correct.

Page 25: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

25

The GridView Control

Exhibit 12-24: The GridView Control

Once the Data Source control is configured, drag a GridView control onto the design so it can be used to display the data.

Page 26: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

26

GridView Common Tasks

Exhibit 12-25: Common GridView Tasks

Use the GridView Common Tasks to choose a data source to display through the GridView.

Page 27: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

27

Additional Common Tasks

Exhibit 12-26: The GridView After Selecting theData Source

Once a data source is selected for the GridView, the common tasks will include additional options for paging, sorting and other features such as Auto Format.

Page 28: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

28

Auto Formatting

Exhibit 12-27: Auto Format Options for the GridView

When you select a scheme from the list on the left, an example will be displayed at the right.

Page 29: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

29

The Finished Design

Exhibit 12-28: The Final Design for the Application

Page 30: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

30

Oracle Data Sources

Exhibit 12-29: Selecting the Oracle Data Source

The SqlDataSource can also be used for accessing data in an Oracle database. In the wizard, simply select “Oracle Database”.

Page 31: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

31Exhibit 12-30: Setting Connection Propertiesin the Oracle Data Source

Oracle Data Sources

To connect to an Oracle database, specify a server name, user name and password.

Page 32: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

32Exhibit 12-31: Selecting an Oracle Data Connection

Oracle Data Sources

An Oracle Data Source will be named with the server name and user name.

Page 33: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

33Exhibit 12-32: Saving the Oracle Connection

Oracle Data Sources

Like SQL Server data sources, an Oracle data source can also be saved in the web.config file.

Page 34: DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH

Database Design and Development: A Visual Approach © 2006 Prentice Hall

Chapter 12

34Exhibit 12-33: Configuring the Select Statement

Oracle Data Sources

The select statement for an Oracle database is constructed the same way as SQL Server.