13.07.2015 Views

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>in</strong> the RowError property of the correspond<strong>in</strong>g row. The batch updateprocess cont<strong>in</strong>ues with subsequent rows.• Last-w<strong>in</strong> Your change is applied regardless of the current status of therow. To implement this approach, you have only to ensure that the SQLcommand used to carry the update is not too restrictive to generate adata conflict. A data conflict occurs when the SQL command f<strong>in</strong>ds norow to affect. If you build the SQL command so that it updates or deletesrows that match a primary key field, no data conflict will ever be raised.Conflict-aware SQL code is code generated by ADO.<strong>NET</strong> commandbuilders <strong>in</strong> which the WHERE clause ensures that the current status andthe orig<strong>in</strong>al status of the row match prior to proceed<strong>in</strong>g with thestatement.• Ask-the-user Take this route when neither of the two preced<strong>in</strong>g optionswill work <strong>in</strong> all possible cases you <strong>for</strong>esee handl<strong>in</strong>g. By default, a dataconflict raises a DBConcurrencyException exception. This exception isnot raised if you set the Cont<strong>in</strong>ueUpdateOnError property to true. TheRow property of the exception class returns a reference to the row <strong>in</strong>error. By read<strong>in</strong>g the properties of such a DataRow object, you haveaccess to both proposed and orig<strong>in</strong>al values. You have no access to theunderly<strong>in</strong>g value, but you can obta<strong>in</strong> that value by issu<strong>in</strong>g another queryaga<strong>in</strong>st the database. Resolv<strong>in</strong>g the conflict ultimately means opt<strong>in</strong>geither <strong>for</strong> a first-w<strong>in</strong> or a last-w<strong>in</strong> approach, but you let the user decidewhich. Your goal is to provide the user with enough <strong>in</strong><strong>for</strong>mation to makethe correct choice.The follow<strong>in</strong>g code uses the "ask-the-user" approach <strong>for</strong> resolv<strong>in</strong>g update dataconflicts:OleDbDataAdapter da = new OleDbDataAdapter();da.Cont<strong>in</strong>ueUpdateOnError = true;da.SelectCommand = new OleDbCommand("SELECT * FROM employees",m_conn);OleDbCommandBuilder cb = new OleDbCommandBuilder(da);da.Update(m_dataSet, "Employees");Figure 10-10 shows the sample application when a change fails.384

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!