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.

Although this solution is clearly not optimal, because unchanged columns are storedtwice, it closely reflects the <strong>in</strong>ternal architecture of the DataRow object and, as such,speeds up the restoration of the DataRow object <strong>in</strong> the dest<strong>in</strong>ation DataTable object.NoteThe DataRow class ma<strong>in</strong>ta<strong>in</strong>s its various versions by implement<strong>in</strong>gan array of subobjects—one <strong>for</strong> the current values, one <strong>for</strong> theorig<strong>in</strong>al version, and one <strong>for</strong> <strong>in</strong>termediate proposed values. Other<strong>in</strong>ternal properties <strong>in</strong>dicate at any moment which is the currentversion and what the state of the row is.As a f<strong>in</strong>al note, consider that <strong>for</strong> each column <strong>in</strong> a DataRow object, only the orig<strong>in</strong>al andthe current values are tracked, and no <strong>in</strong>termediate values are buffered. For example,suppose that you per<strong>for</strong>m the follow<strong>in</strong>g operation on an unchanged row:// 1 is the current value of the fieldrow[0][field] = 2;The row state changes to Modified, the orig<strong>in</strong>al value (1) is persisted <strong>in</strong> the Orig<strong>in</strong>alcopy of the row, and the new value (2) is registered as the current value. Next thefollow<strong>in</strong>g code runs:// 2 is the current value of the field// 1 is the orig<strong>in</strong>al value of the fieldrow[0][field] = 3;// 3 is NOW the current value of the field// 1 is the orig<strong>in</strong>al value of the fieldThe orig<strong>in</strong>al copy of the row rema<strong>in</strong>s <strong>in</strong>tact, but the current version is updated. As aresult, the <strong>in</strong>termediate value (2) is overwritten and is irreversibly lost.NoteBuild<strong>in</strong>g an automatic mechanism <strong>for</strong> track<strong>in</strong>g the entire history of arow is probably unnecessary <strong>in</strong> most cases. If you need a morepowerful mechanism to track changes, you can build a parallel tableof changes <strong>for</strong> each row <strong>in</strong> the table. Each entry <strong>in</strong> the custom tablewould po<strong>in</strong>t to a particular DataRow object and conta<strong>in</strong> a collectionof changes organized as you prefer.Track<strong>in</strong>g Pend<strong>in</strong>g ErrorsThe DataRow class provides a few methods <strong>for</strong> handl<strong>in</strong>g row errors. You can set ageneral error message on the entire row, and you can set a column-specific message.To set a general error message, you use the RowError property. To set a columnspecificmessage, you use the pair of methods SetColumnError and GetColumnError.Other helper methods available are GetColumnsInError and ClearErrors.A column or row with an error is <strong>in</strong> no way different from a column or row withoutpend<strong>in</strong>g errors. In this context, an error is simply a description of contents that the user,or the application, f<strong>in</strong>ds erroneous and <strong>in</strong>consistent. Noth<strong>in</strong>g prevents you from us<strong>in</strong>gerror properties as general-purpose cargo variables <strong>in</strong> which to store custom<strong>in</strong><strong>for</strong>mation and annotations.NoteIf you choose to use error properties as general-purpose cargovariables, keep <strong>in</strong> m<strong>in</strong>d that some advanced W<strong>in</strong>dows Forms andWeb Forms controls can, <strong>in</strong> the presence of error flags, refresh theirown user <strong>in</strong>terfaces accord<strong>in</strong>gly. For example, the W<strong>in</strong>dows Forms370

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

Saved successfully!

Ooh no, something went wrong!