• Like
  • Save
Vb net xp_07
Upcoming SlideShare
Loading in...5
×
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
455
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Performing Data UpdatesObjectivesIn this lesson, you will learn to:Perform cached data updatesPerform direct data updatesIdentify the need for concurrency managementIdentify the methods of maintaining concurrency in datasets ©NIIT Performing Data Updates/Lesson 7/Slide 1 of 25
  • 2. Performing Data UpdatesProblem Statement 7.D.1The Diaz Telecommunications Sales Manager needs to viewthe customer details in a customized format. In addition, thecustomer details need to be maintained, which involvesadding new customer details, and modifying and deleting theexisting ones. ©NIIT Performing Data Updates/Lesson 7/Slide 2 of 25
  • 3. Performing Data UpdatesTask ListIdentify the data that needs to be maintained.Identify the mechanism to maintain data.Design a Windows Form to maintain the data.Connect to the database.Bind the data to the Windows Form controls.Write the code to maintain the data.Perform data maintenance. ©NIIT Performing Data Updates/Lesson 7/Slide 3 of 25
  • 4. Performing Data UpdatesTask 1: Identify the data that needs to be maintained.Result:As per the given problem statement, the data to bemaintained is as follows:  CustID  FName  LName  Address  Phone  email ©NIIT Performing Data Updates/Lesson 7/Slide 4 of 25
  • 5. Performing Data UpdatesTask 2: Identify the mechanism to maintain data.Data can be retrieved from a database directly throughdata commands or cached in datasets.Performing cached data updates  Updating the dataset ® While updating the dataset, some events are raised: ® ColumnChanging ® RowChanging ® ColumnChanged ® RowChanged ® RowDeleting ® RowDeleted ©NIIT Performing Data Updates/Lesson 7/Slide 5 of 25
  • 6. Performing Data UpdatesTask 2: Identify the mechanism to maintain data.(Contd.) ® Whileupdating the dataset, the following information is maintained: ® RowState property ® Unchanged ® Added ® Deleted ® Detached ® Modified ©NIIT Performing Data Updates/Lesson 7/Slide 6 of 25
  • 7. Performing Data UpdatesTask 2: Identify the mechanism to maintain data.(Contd.) ® DataRowVersion Enumeration ® Original ® Current ® Proposed ® Default ® The changes are committed to the dataset by calling the AcceptChanges()method.  Updating the data source ® Thedata source is updated with the changed dataset by calling the Update()method of the data adapter. ©NIIT Performing Data Updates/Lesson 7/Slide 7 of 25
  • 8. Performing Data UpdatesJust a Minute…2. When does the RowState property have the value Detached?3. What is the relationship between the RowState property and the DataRowVersion enumeration? ©NIIT Performing Data Updates/Lesson 7/Slide 8 of 25
  • 9. Performing Data UpdatesTask 2: Identify the mechanism to maintain data.(Contd.)Performing direct data updates  Data commands are can be used to directly update the data source.  A data command object can be derived from the OleDbCommand class or the SqlCommand class.  For executing a data command, the Connection, CommandText, and the Parameters properties for the data command have to be set. ©NIIT Performing Data Updates/Lesson 7/Slide 9 of 25
  • 10. Performing Data UpdatesTask 2: Identify the mechanism to maintain data.(Contd.)Result:Since you need to access the data through a dataset, you will perform a cached data update. ©NIIT Performing Data Updates/Lesson 7/Slide 10 of 25
  • 11. Performing Data UpdatesJust a Minute…1. In which cases, direct data update is preferred to updates through datasets?2. Write a code to connect to a database through data commands. ©NIIT Performing Data Updates/Lesson 7/Slide 11 of 25
  • 12. Performing Data UpdatesTask 3: Design a Windows Form to maintain the data.Task 4: Connect to the database.Task 5: Bind the data to the Windows Form controls.Task 6: Write the code to maintain the data.Task 7: Perform data maintenance. ©NIIT Performing Data Updates/Lesson 7/Slide 12 of 25
  • 13. Performing Data UpdatesMaintaining Data ConcurrencyConcurrency control is the process of ensuring that in case many people attempt to modify data in a database atthe same time, modifications made by one person do not adversely affect those of another person. Method Description Pessimistic concurrency control In this type of concurrency control, a system of locks applied does not allow users to modify data in a way that affects other users. When a lock is applied, other users cannot perform actions that would conflict with the lock until the owner releases it. Pessimistic control is mainly used in environments where the data contention is high and protecting data with locks is less costly than rolling back transactions in case of concurrency conflicts. Pessimistic concurrency is not possible in a disconnected architecture. ©NIIT Performing Data Updates/Lesson 7/Slide 13 of 25
  • 14. Performing Data UpdatesMaintaining Data Concurrency (Contd.) Method Description Optimistic concurrency control In this type of concurrency control, the lock is not applied when the users read the data. When the user performs a data update, the system checks to see if the data has been changed by another user after the data was read. If the data has been changed, an error is raised. Optimistic concurrency is used in environments where the data contention is low and protecting data with locks is more costly than rolling back transaction in case of concurrency conflicts. ‘Last in Wins’ concurrency control This type of concurrency control works in a similar way as the optimistic concurrency control, with the difference that the record is updated regardless of whether the record has been changed or not. ©NIIT Performing Data Updates/Lesson 7/Slide 14 of 25
  • 15. Performing Data UpdatesMaintaining Data Concurrency (Contd.)ADO.NET implements optimistic concurrency by using the following two methods:  The Version number method ® Theversion number method requires the record to be updated to have a datetime stamp or a version number column.  The saving all values method ® When the data is retrieved, a copy of all fields, that is, the original version is maintained on the client. ©NIIT Performing Data Updates/Lesson 7/Slide 15 of 25
  • 16. Performing Data UpdatesJust a Minute…What is the difference between the concurrency controlthrough the Saving All method and the Version Numbermethod? ©NIIT Performing Data Updates/Lesson 7/Slide 16 of 25
  • 17. Performing Data UpdatesOptimistic Concurrency through Data AdapterBy default, the data adapters that are created in anapplication implement optimistic concurrency. ©NIIT Performing Data Updates/Lesson 7/Slide 17 of 25
  • 18. Performing Data UpdatesProblem Statement 7.P.1The Sales Manager of Diaz Telecommunications needs tomaintain customer details, which involves adding newcustomer details, and modifying and deleting existingcustomer details. While adding and modifying details, theapplication should ensure that no field is left blank. ©NIIT Performing Data Updates/Lesson 7/Slide 18 of 25
  • 19. Performing Data UpdatesSummaryIn this lesson, you learned that:Data can be retrieved from a database directly through data commands or can be cached in datasets.When a dataset is used to access data, updating thedatabase consists of two steps, updating the dataset andupdating the database.When you make changes to a record in the table, thefollowing events are raised by the DataTable object:  ColumnChanging  RowChanging  ColumnChanged ©NIIT Performing Data Updates/Lesson 7/Slide 19 of 25
  • 20. Performing Data UpdatesSummary (Contd.)  RowChanged  RowDeleting  RowDeletedThe ColumnChanging and RowChanging events raised by the DataTable object are used to validate the dataset while updating it.When changes are made in a dataset, that is, a row is added, deleted, or modified, some information about each update has to be maintained. ©NIIT Performing Data Updates/Lesson 7/Slide 20 of 25
  • 21. Performing Data UpdatesSummary (Contd.) The data adapter uses the following information while updating the data source:  The RowState property — The RowState property of the DataRow object indicates the current state of the record.  The DataRowVersion enumeration — A dataset can maintain four versions of a DataRow object: Current, Original, Proposed, and Default. After the changes have been made, they are committed to the dataset by calling the AcceptChanges() method of the dataset to accept the changes made to the dataset. ©NIIT Performing Data Updates/Lesson 7/Slide 21 of 25
  • 22. Performing Data UpdatesSummary (Contd.)The data source is updated with the changed dataset bycalling the Update() method of the OleDbDataAdapter class.Data commands are generally used in the following cases:  To work with stored procedures that return a result set, which can be manipulated  To access data that is not appropriate for storing in a dataset, such as data with a short life cycle  To access read-only data, that is, data that will not be updated A data command object can be derived from theOleDbCommand class or the SqlCommand class. ©NIIT Performing Data Updates/Lesson 7/Slide 22 of 25
  • 23. Performing Data UpdatesSummary (Contd.)A data command object can be derived from theOleDbCommand class or the SqlCommand class.For executing a data command, the Connection and the CommandText properties for the commandhave to be set for specifying the connection and theSQL query to be executed to retrieve the data,respectively.‘Concurrency’ means ‘at the same time’; thus,concurrency management means to decide the action that will take place when multiple users try toupdate the same record. ©NIIT Performing Data Updates/Lesson 7/Slide 23 of 25
  • 24. Performing Data UpdatesSummary (Contd.) There are three concurrency management methods available:  Pessimistic concurrency control — In this type of concurrency control, a record is not available to other users from the time that a user begins to edit the record till the time that the record is updated in the database.  Optimistic concurrency control — In this type of concurrency control, the record is not available to other users only when the record is being updated in the database. When a user tries to update a record that has been changed, an error occurs. ©NIIT Performing Data Updates/Lesson 7/Slide 24 of 25
  • 25. Performing Data UpdatesSummary (Contd.)  Last in Wins concurrency control — This type of concurrency control works similar to the optimistic concurrency control, the only difference being that the record is updated without checking whether the record has been changed or not. When the row is changed and there is an attempt to update the database, ADO.NET uses two methods to determine if any changes have occurred:  The Version number method  The saving all values method By default, the data adapters that are created in an application implement optimistic concurrency. ©NIIT Performing Data Updates/Lesson 7/Slide 25 of 25