Starting in 1996, Alexa Internet has been donating their crawl data to the Internet Archive. Flowing in every day, these data are added to the Wayback Machine after an embargo period.
As mentioned earlier in the chapter and illustrated in the section entitled "Deleting and Removing Rows," the DataRow class defines a property called RowState that is a DataRowState enumeration with the values shown in Table 6-2.
Quick Note on This Section's Examples
This section's code snippets are all freestanding functions that can be plugged directly into your own test applications.They make the sole assumption that the DataSet and CommandBuilder objects have all been properly contructed. For example, in an SDI applicatinon you might declare each of these as member variables of the view and instantiate them (as illustrated in the section entitled "Contructing and Filling DataSet Objects") in the view's OnInitialUpdate function. This way, you can follow along, trying the various code snippets without having to see the same connection code repeasted over and over in each code example.
Table 6-2DataRowState Enumeration Values
Member Name
Description
Added
The DataRow object has been added to the DataRowCollection object, but DataRow::AcceptChanges has not been called.
Deleted
The DataRow object—belonging to a DataRowCollection—has been deleted using the DataRow::Delete method.
Detached
Either the DataRow object has not been added to the collection or it has been removed via either the DataRowCollection::Remove or DataRowCollection::RemoveAt method.
Modified
The DataRow object—belonging to a DataRowCollection—has been edited, but DataRow::AcceptChanges has not been called.
Unchanged
The DataRow object—belonging to a DataRowCollection—has not changed since the last time DataRow::AcceptChanges was called.
As you can you can see, these enumeration values cover the various states of a DataRow. In fact, you can use the Visual Studio .NET debugger with the EmployeeMaintenance demo application and easily see the various states of the respective DataRow objects as you add, edit, and delete employee records. The following example illustrates the manipulation of a DataRow object and the impact of those changes on the object's RowState property. (As you've already seen examples of connecting to and reading existing data into DataSet objects, this code also illustrates how to manually define your own DataSet and DataTable objects from application data. It's not something you'll use every day, but it's definitely useful at times.)
Plugging these two functions into a Win32 console application with Managed Extensions support and the appropriate using directives would result in the following output:
Created new row DataRowState::Detached
Added new row DataRowState::Added
Accepted changes DataRowState::Unchanged
Edited row DataRowState::Modified
Deleted row DataRowState::Deleted
While most of this is what you'd expect after seeing the DataRowState enumeration descriptions in Table 6-2, there are a couple of things of note. First, a newly created DataRow has its RowState set to Detached until it is added to the DataRowCollection via the DataRowcollection::Add method. At that point, the RowState is initialized to Added until the DataRow::AcceptChanges method is called, at which point the RowState becomes Unchanged. Finally, note that if you call DataRow::Delete, the row's RowState becomes Deleted, and subsequently calling DataRow Collection::Remove (or DataRowCollection::RemoveAt) will not affect its RowState. The opposite is also true: Removing a DataRow from a Data RowCollection sets the row's RowState to Detached, but subsequently deleting it will not alter its RowState value.
About the Author
I am a Program Manager and Content Strategist for the Microsoft MSDN Online team managing the Windows Vista and Visual C++ developer centers.
Before being employed at Microsoft, I was awarded MVP status for the Visual C++ product. A 20+ year veteran of programming with various languages - C++, C, Assembler, RPG III/400, PL/I, etc. - I've also written many technical books (Inside C#, Extending MFC Applications with the .NET Framework, Visual C++.NET Bible, etc.) and 100+ online articles.
Tools:
Add www.codeguru.com to your favorites Add www.codeguru.com to your browser search box IE 7 | Firefox 2.0 | Firefox 1.5.xReceive news via our XML/RSS feed
RATE THIS ARTICLE:
Excellent Very Good Average Below Average Poor
(You must be signed in to rank an article. Not a member? Click here to register)
Latest Comments:
No Comments Posted.
Add a Comment:
Title:
Comment:
Pre-Formatted:
Check this if you want the text to display with the formatting as typed (good for source code)
(You must be signed in to comment on an article. Not a member? Click here to register)