Other Updating Concerns

Chapter 11

Advanced Updating Scenarios

In Chapter 10, you learned how to use the updating features of the DataAdapter object to submit changes to your database. At this point, you should be comfortable generating updating logic using either the Visual Studio .NET Data Adapter Configuration Wizard or the CommandBuilder object. You should also feel comfortable with the UPDATE, INSERT, and DELETE SQL queries that these tools generate to translate the pending changes stored in your DataSet into changes in your database.

All the examples in Chapter 10 involve simple updating scenarios. All of the updates succeed. After you submit the changes, there is no need to requery the database for any information. The tables used in the code snippets do not have columns of server-generated data such as autoincrement values or timestamps, and changes are submitted to only a single table. You will likely face more challenging updating scenarios in your applications, however.

For example, if you're working with tables that have autoincrement columns, you'll want to retrieve the autoincrement values that your database generates for new rows. In other situations, you'll want to refetch the contents of your row after you submit an update, such as when you're relying on timestamp columns to enforce optimistic concurrency.

The more complex your application is, the more complex the updating scenarios you'll likely face. Submitting changes to hierarchical data can prove challenging. Multi-tiered applications pose their own special set of problems—such as transmitting DataSet objects that contain only the data required to submit updates to your database and reintegrating newly fetched values such as timestamps and autoincrement values into a preexisting DataSet.

Optimistic update attempts don't always succeed. For example, your update attempts might fail if another user has modified the rows you wanted to update. You're probably better off learning to handle such failures elegantly rather than going to extreme lengths to try to prevent the failures in the first place.

This chapter will take a closer look at these and other advanced updating scenarios. However, I'll be taking a slightly different approach. Previous chapters are peppered with code snippets that you can copy and paste into console applications and run successfully without having to change the code. Creating fully functional code snippets for advanced updating scenarios in this chapter would be unrealistic. So this chapter will instead use small snippets of code from sample applications on the companion CD.



Microsoft ADO. NET Core Reference
Microsoft ADO.NET (Core Reference) (PRO-Developer)
ISBN: 0735614237
EAN: 2147483647
Year: 2002
Pages: 104
Authors: David Sceppa

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net