Académique Documents
Professionnel Documents
Culture Documents
Slide 1
Objectives
Knowledge In general, describe the use of these ADO.NET objects when youre using datasets to get data from a database: dataset, data adapter, command, and connection. In general, describe the use of these ADO.NET objects when youre using code to get data from a database: data reader, command, and connection. Describe concurrency, optimistic concurrency control, and last in wins. Describe the use of the .NET data providers. Describe these methods of the SQLConnection class: Open, Close. Describe these methods of the SqlCommand class: ExecuteReader, ExecuteNonQuery.
Slide 2
Objectives (continued)
Describe these methods of the SqlDataAdapter class: Fill, Update. Describe these methods of the SqlDataReader class: Read, Close. Describe these objects in the basic dataset object hierarchy: dataset, data table, data column, data row, and constraint. Describe the two layers in the structure of an application that uses datasets. Describe the three layers in the structure of an application that uses business classes.
Slide 3
Command
Database server
Connection Database
Slide 4
Slide 5
Slide 6
Slide 7
Slide 8
Two ways to create the ADO.NET objects for working with datasets
You can use the Data Sources window in Visual Studio to create a data source. Then, you can drag the data source onto the form to automatically generate a table adapter object and a dataset object. A table adapter is like a data adapter, but it has a built-in connection object, and it can contain more than one query. To create ADO.NET objects in code, you write declarations that identify the class each object is created from.
Slide 9
Select command
Database server
Connection Database
Slide 10
Slide 11
Slide 12
Two users who are working with copies of the same data
Database server
Slide 13
What happens when two users try to update the same row
When two or more users retrieve the data in the same row of a database table at the same time, it is called concurrency. Because ADO.NET uses a disconnected data architecture, the database management system cant prevent this from happening. If two users try to update the same row in a database table at the same time, the second users changes could overwrite the changes made by the first user. Whether that happens depends on the concurrency control that the programs use.
Slide 14
Concurrency control
By default, ADO.NET uses optimistic concurrency. The program checks to see whether the database row thats going to be updated or deleted has been changed since it was retrieved. If it has, a concurrency exception occurs and the update or deletion is refused. Then, the program should handle the exception. If optimistic concurrency isnt in effect, the change/delete operation proceeds without throwing an exception. This is referred to as last in wins because the last update overwrites any previous update. And this leads to errors in the database.
Slide 15
Slide 16
Slide 17
Slide 18
Slide 19
Slide 20
Slide 21
Slide 22
Slide 23
Slide 24
Slide 25
Update
Slide 26
Slide 27
Slide 28
Data table
Data column
Data row
Constraint
Data relation
Slide 29
Slide 30
Slide 31
Slide 32
Slide 33
Slide 34
Slide 35
Code that refers to the rows collection in the tables collection of a dataset
Dim message As String For Each dr As DataRow In vendorsDataSet.Tables("Vendors").Rows message &= dr.Item("Name") & vbCrLf Next MessageBox.Show(message)
Slide 36
Presentation layer
Dataset classes
Database layer
Database
Slide 37
Middle layer
Business classes
Database layer
Database classes
Database
Slide 39
Slide 40
Slide 41