NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Removing Versus Deleting a DataRow from a Table

As you work with data in a table there will be times when you want to remove one or more rows from the table. Note, however, that "removing" a row is not the same as "deleting" a row as Deleted. "Removing" a row means physically removing the row from the DataSet. This distinction will be important later in the discussion of persisting the values in the table to a data store.

To remove a row from the table call the Remove method of the table's RowsCollection (accessed through the DataTable object's Rows property) with either the index of the row or the actual instance of the row.

[VB]
workTable.Rows.Remove(3)
[C#]
workTable.Rows.Remove(3);

or

[VB]
workTable.Rows.Remove(workTable.Rows(3))
[C#]
workTable.Rows.Remove(workTable.Rows[3]);

After calling this method, the specified row will be removed from the rows collection.

In contrast, you can call the Delete method on a DataRow to change its state to Deleted:

[VB]
workTable.Rows(3).Delete
[C#]
workTable.Rows[3].Delete

Marking a row as deleted signals that when the DataTable object's AcceptChanges method is invoked, the row will be removed from the table. Thus the RowState for the row is Deleted. In contrast, if RejectChanges is invoked, this row's RowState will revert to what it was before being marked as deleted.

The difference between the Remove and Delete methods is when the actual removal takes place.

Note   If a row's RowState is New, meaning its just been added to the table, and it is then marked as Deleted, it will be removed from the table.