cis266 final review
TRANSCRIPT
![Page 1: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/1.jpg)
FINAL REVIEWCIS266
![Page 2: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/2.jpg)
Use the DataSet object
To transfer data between tiers To manipulate the data without an
open connection To relate data from multiple sources To bind data to a Windows form
![Page 3: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/3.jpg)
Referring to Records, Fields Actual data values are held in
DataRow objects Each Table object in a dataset has a
DataRows collection made up of DataRow objects
Data values are held in the DataRow.Items collection Refer to fields by index position or by
name (string value)
![Page 4: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/4.jpg)
Setting a Relationship
A DataRelation object describes the relationship between the tables.
Use the XML schema (.xsd) file for the dataset to create the relationship – or – use code to create a relation
DataRelation Object Functions Relating tables Setting up constraints
![Page 5: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/5.jpg)
Retrieving Related Row(s)
Use the GetParentRow method to retrieve the matching row from the table on the one side
The GetChildRows method returns an array of rows from the many table May have 0, 1, or more related records
Use Find method to find a row by its primary key value
![Page 6: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/6.jpg)
DataRowState Enumeration
Used for finding, accessing changed rows The HasChanges Method determines if
changes have been made to a dataset Returns a boolean value
The GetChanges Method is used to retrieve datatable rows that have changes Use an empty argument to retrieve all
changed rows OR specify type of changes using enumeration values
![Page 7: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/7.jpg)
The Binding Source
Controls record position within a table
Assures that all bound controls on a form display data from the same record
Can bind controls in design time or in code
![Page 8: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/8.jpg)
Binding Source Properties
Position property holds the current row number (zero based)
Count property indicates the number of records in a table
The Current Property returns the current row
![Page 9: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/9.jpg)
Binding Source Methods
Binding Source Events The CurrentChanged event occurs
when a bound value is changed The PositionChanged event occurs
when a user navigates to another record
![Page 10: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/10.jpg)
Adding an Event Handler
An event handler executes automatically when an event occurs.
Need to write event handlers for objects declared in code Write the procedure you want to execute
when the event occurs, including the sender and eventargs arguments
Add the handler in another procedure (such as constructor), which is called a delegate turns the general procedure written into an
event procedure
![Page 11: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/11.jpg)
DataRow Versions
The DataRow object maintains several versions of its column data Current, Original, Default, Proposed
If no changes have been made, the Current and Original versions are the same
When EndEdit executes, the Current version is replaced by the Proposed
The EndEdit method confirms the changes Changes are made when the
AcceptChanges method executes
![Page 12: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/12.jpg)
Changing Data
Changes are made to the dataset, not to the original data source.
Execute the data adapter’s Update method before calling the AcceptChanges method.
![Page 13: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/13.jpg)
The AcceptChanges Method
Calls the EndEdit method of the data row Removes all rows marked for deletion Makes the adds and edits indicated for the table Sets the Original version of each changed row
to the Current version Sets RowState of each row to Unchanged The RejectChanges replaces Current versions
with the Original versions After AcceptChanges or RejectChanges
executes, all RowState properties are reset to Unchanged
![Page 14: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/14.jpg)
Data Adapter Update Method Update writes the changes to the
database using SQL action queries Uses a group of Command Objects
One each for insert, update and delete Can use actual queries or refer to stored
procedures
![Page 15: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/15.jpg)
When to Update?
Every time an add, edit, delete occurs?
When the program terminates? Provide a Save option on a menu and
prompt for unsaved changes when the program terminates?
![Page 16: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/16.jpg)
Update Considerations
Where does the application and data reside?
How many users can make changes? Does the data source need to be up-
to-date at all times?
![Page 17: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/17.jpg)
Concurrency
Concurrency control is the process of handling conflicts in updates by multiple users.
Pessimistic concurrency control – a row is unavailable from the time the record is retrieved until the update is complete
Optimistic concurrency control – a row is unavailable only while an update is in progress (default)
“Last in wins” – A row is unavailable only when the update is being made.
![Page 18: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/18.jpg)
Parent/Child Relationships To maintain referential integrity,
update in the following order: Delete any child records Insert, update, and delete the parent
records Insert and update the child records
![Page 19: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/19.jpg)
Displaying Related Data
Use a DataRelation Use GetChildRows/GetParentRow methods Use a Binding Source that uses a Datarelation as
its datasource Filter rows by
Using a For loop and adding to an array or datable
Use table.Select method Requery database for related records
Use Parameter Query; or Use a variable and build a Select statement with
where clause
![Page 20: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/20.jpg)
Stored Procedures
Can store compiled SQL statement in database Helps reduce security threats Can reduce data passed across network
Typically work directly with a command object Need to set command type Need to establish connection for
command
![Page 21: Cis266 final review](https://reader036.vdocuments.us/reader036/viewer/2022062706/55789d2ed8b42aaf518b4e3b/html5/thumbnails/21.jpg)
Parameters
Stored procedures accept and return values through parameters Input parameters are similar to
arguments in procedural languages Command object has a parameters
collection to specify parameters to use with stored procedure
Can use parameters to pass criteria or values to edit rows