Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming the Web Using ASP.Net

Similar presentations


Presentation on theme: "Programming the Web Using ASP.Net"— Presentation transcript:

1 Programming the Web Using ASP.Net
Chapter 8: Introduction to ADO.Net Dave Mercer McGraw-Hill/Irwin

2 Objectives Explain how ADO.Net and ASP.Net are related
Describe the major ADO.Net structures and objects Make a connection to a SQL Server database from an ASP.Net application Retrieve records from a SQL server database Bind records to ASP.Net Web Server controls Build a registration and login process for a Web application Build a Web application that supports multi-player games

3 ADO.Net and Databases ADO.Net is Microsoft’s latest iteration of Active Data Objects, a class from which objects can be derived that are highly useful in making database connection, running database commands, and retrieving records as results. Basically, ADO.Net is a set of objects you can call from your ASP.Net application that allows you to retrieve and manipulate records from a data store, such as SQL Server.

4 Data Providers Data in databases can be located on any accessible server, not just the local machine. To reach the data, retrieve it and manipulate it, you use a data provider.

5 ADO.Net Classes Like ASP.Net, ADO.Net is a set of classes from which objects can be derived. The classes include such things as DataAdapters, DataReaders, DataSets, and DataTables. The objects derived from these classes are optimized for retrieving and manipulating records with context and structure very similar to the database from which they are pulled.

6 Making Database Connections
ADO.Net Connection objects allow you to make a connection to a database in your Web application. Connections are made with connection strings, short strings of name/value pairs that identify the database file, location, username and password, and other necessary data. There are two types of Connection objects available: the SQLConnection (for SQL Server 7.0 or higher) and the OleDbConnection.

7 The SQLConnection Object
The SQLConnection object is useful for making connections to SQL Server databases. It uses a connection string to connect to the database file. Once it makes the connection, commands can be executed programmatically against the database file, in much the same way that you might manually retrieve or change records using Enterprise Manager.

8 SQLConnection Class Properties
Important properties of the SQLConnection class include: ConnectionString: The data to be used to make a connection ConnectionTimeout: The length of time to try to make the connection State: Whether the connection is currently open or closed

9 SQLConnection Class Methods
Important methods of the SQLConnection class include: Open: Opens the connection Close: Closes the connection Dispose: Releases the resources used by the connection

10 Running Database Commands
Once a connection has been made, you can run commands against the database. Commands include SELECT, INSERT, UPDATE, and DELETE. The SQLCommand (for SQL server 7.0 or higher) and OleDbCommand objects are used to run commands, and are available in the Toolbox as well.

11 Running Database Commands (2)
There are several types of Execute method available with the SQLCommand object: ExecuteReader ExecuteScalar ExecuteNonQuery, and ExecuteXMLReader

12 The DataAdapter The DataAdapter object lets you retrieve the entire structure of a database and manipulate it locally, and then update the remote database. The DataAdapter uses Connection and Command objects to make a connection, retrieve, and manipulate records.

13 DataAdapter and DataSet
The DataAdapter object can be used to retrieve records and place them in a DataSet. The DataSet is a high-level object that acts like an entire database represented as an object with collections of child objects for tables, relations, rows, and columns. When you use a DataAdapter to fill a DataSet, you then have the capability to work with records from the database as though you were directly manipulating the database.

14 ASP.Net Web Application Validation Controls
There are two ways you can perform validation: on the client and on the server. Both validation methods can be useful. While client-based validation is handy, it can easily be defeated by sophisticated users. Server-based validation is a backup to client-based validation and is not easy to circumvent. VS.Net has several controls available for validation functions.

15 Validation Controls in VS.Net
Built-in validation controls appear in the Web Server controls portion of the Toolbox when you are working on a Web form: the RequiredFieldValidator the CompareValidator the RangeValidator the RegularExpressionValidator the CustomValidator, and the ValidationSummary. If invalid values are present, the user receives your specified message immediately.

16 Regular Expressions While a validation control cannot ensure accurate data, you can use the RegularExpressionValidator to ensure that the data matches a pattern that is consistent with the type of data you expect to be entered. You’ll find a number of regular expression patterns already available in VS.Net.

17 The End


Download ppt "Programming the Web Using ASP.Net"

Similar presentations


Ads by Google