Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)

Similar presentations


Presentation on theme: "Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)"— Presentation transcript:

1 Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)

2 Objectives Understand database processing using ADO.NET
Perform specialized database processing tasks Work with database data programmatically using either DataReaders (connected mode) DataSets (disconnected mode) We discuss DataReaders here

3 DataReader The DataReader is a component used for read-only and forward-only connection to a database. Results are returned as a query executes and stored in the network buffer on the client until you request them using the Read method of the DataReader. Using the DataReader can increase application performance both by retrieving data as soon as it is available, and (by default) storing only one row at a time in memory, reducing system overhead. It is used to execute a query via a connection to a database and iterate through the data returned. The abstraction provided here is that of a connected data architecture.

4 DataReader

5 The Processing Sequence
Holds for both connected and disconnected architectures Establish a connection to your data source using a Connection Object These objects are simple to construct Create an SQL statement (a string) and wrap it in a Command object These strings are harder to build – more detailed Execute the Command object within the context of the Connected DB – there are methods for this Process (retrieve or store) results of command if there are any Use a DataReader object to scan through records Close all objects you opened to process data

6 The Primary Objects The Connection Object – Directs communication between your program and Data Source. Handles location and connection parameters for the data source. The Command Object – Takes an SQL statement you provide (as a string) and prepares it for transport through the Connect-ion Object and subsequent processing in the specified DBMS. The DataReader Object – Provides a simple and efficient way to retrieve results from an SQL query. It is used by other objects in ADO.NET to retrieve and redirect data within your program. You can use this reader directly to process the result of a SELECT or other retrieval action.

7 DataReader Example

8 Example: Insert a Record

9 Example: Delete a Record

10 Example: Update a Record

11 DataReaders – main use DataReaders
Simple and efficient way to retrieve results from a query Can use directly to process results of a SELECT or to provide direct access INSERTs, DELETEs, and UPDATEs A query gives you access to one row of table information at a time Your connection must be open before a command is executed and should be closed when you are done

12 Using DataReaders

13 The OleDbCommand Class
The OleDbCommand class stores SQL statements The Connection property stores a reference to an OleDbConnection The CommandText property stores an SQL statement The CommandType property should be set to Text

14 Example 1 – Insert (plus a simple select) (Uses Insert and DataReader commands to effect data transmission)

15 Example 2 – Using Max Transaction ID
Commit list of transactions to a DB – quote corrections needed

16 Example 3 – Delete (remove) a record (quote corrections needed)

17 Example 4 – Update a Record-(quote corrections needed)


Download ppt "Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)"

Similar presentations


Ads by Google