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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

If no match is found, ReadXml deduces that the row <strong>in</strong> the section wasdeleted from the table when it was at the position that the msdata:rowOrder attribute<strong>in</strong>dicates. The method <strong>in</strong>serts a new row <strong>in</strong> the table at the same position andpopulates it with the values read from the section. Next the row ismarked <strong>for</strong> deletion us<strong>in</strong>g the Delete method of the DataRow object.The f<strong>in</strong>al step consists of read<strong>in</strong>g the values from the section andupdat<strong>in</strong>g accord<strong>in</strong>gly the RowError property of the correspond<strong>in</strong>g DataRow object <strong>in</strong> thetable.The Row Commit ModelThe DataSet, DataTable, and DataRow objects ma<strong>in</strong>ta<strong>in</strong> a local cache of changes.When a row is modified, deleted, or added, its state changes to one of the values of theDataRowState enumeration. (See the .<strong>NET</strong> Framework documentation <strong>for</strong> details.)Similarly, when a row is added, modified, or deleted from a table, the <strong>in</strong>ternal state ofthe table is altered, result<strong>in</strong>g <strong>in</strong> pend<strong>in</strong>g changes <strong>for</strong> the affected rows.Pend<strong>in</strong>g changes can be either accepted or rejected at the DataSet, DataTable, orDataRow level. Accept<strong>in</strong>g a pend<strong>in</strong>g change means that the row (changes always<strong>in</strong>volve a row) updates are committed to the table. Reject<strong>in</strong>g a pend<strong>in</strong>g change rollsback the state of the table, and the table appears as though the change never occurred.A DiffGram can track pend<strong>in</strong>g changes—that is, <strong>in</strong>-memory changes that have not yetbeen committed. Table 10-3 lists the allowable states <strong>for</strong> a DataRow object.Table 10-3: States of a DataRow ObjectStateAddedDeletedDetachedModifiedUnchangedDescriptionThe row has been added to the table, but AcceptChangeshas not yet been called.The row is marked <strong>for</strong> deletion from the parent table.Either the row has been created but not yet added to thetable, or the row has been removed from the rows collection.Some columns with<strong>in</strong> the row have been changed.No changes have been made s<strong>in</strong>ce the last call toAcceptChanges. This is also the state of all rows when thetable is first created.The AcceptChanges method has the power to commit all the changes and accept thecurrent values as the new orig<strong>in</strong>al values of the table, clear<strong>in</strong>g pend<strong>in</strong>g changes.RejectChanges rolls back all the pend<strong>in</strong>g changes. We'll encounter the row commitmodel aga<strong>in</strong> <strong>in</strong> the section "A Save-And-Resume Application," on page 464, when welook at save-and-resume applications.The Orig<strong>in</strong>al Data SectionThe DiffGram has a layered structure <strong>in</strong> which current values, orig<strong>in</strong>al values <strong>for</strong> themodified rows, and pend<strong>in</strong>g errors are stored <strong>in</strong> dist<strong>in</strong>ct sections. The state of theDataSet object is rebuilt by comb<strong>in</strong><strong>in</strong>g the contents of these sections. The orig<strong>in</strong>alvalues are stored <strong>in</strong> the section as a change with respect to the currentdata <strong>in</strong>stance.The DataRow object ma<strong>in</strong>ta<strong>in</strong>s several versions of itself that are <strong>in</strong>ternally stored <strong>in</strong> anarray of rows. The versions are grouped <strong>in</strong> the DataRowVersion enumeration, shown <strong>in</strong>Table 10-4.368

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

Saved successfully!

Ooh no, something went wrong!