Free mag vol1 | Page 921

CHAPTER 22  ADO.NET PART II: THE DISCONNECTED LAYER Working with DataRows As you have seen, a collection of DataColumn objects represents the schema of a DataTable. In contrast, a collection of DataRow objects represents the actual data in the table. Thus, if you have 20 rows in the Inventory table of the AutoLot database, you can represent these records using 20 DataRow objects. Table 22-4 documents some (but not all) of the members of the DataRow type. Table 22-4. Key Members of the DataRow Type Members Meaning in Life HasErrors GetColumnsInError() GetColumnError() ClearErrors() RowError The HasErrors property returns a Boolean value indicating whether there are errors in a DataRow. If so, you can use the GetColumnsInError() method to obtain the offending columns and GetColumnError()to obtain the error description. Similarly, you can use the ClearErrors() method to remove each error listing for the row. The RowError property allows you to configure a textual description of the error for a given row. ItemArray This property gets or sets all of the column values for this row using an array of objects. RowState You use this property to pinpoint the current state of the DataRow in the DataTable containing the DataRow, using values of the RowState enumeration (e.g., a row can be flagged as new, modified, unchanged, or deleted). Table You use this property to obtain a reference to the DataTable containing this DataRow. AcceptChanges() RejectChanges() These methods commit or reject all changes made to this row since the last time AcceptChanges() was called. BeginEdit() EndEdit() CancelEdit() These methods begin, end, or cancel an edit operation on a DataRow object. Delete() This method marks a row you want to remove when the AcceptChanges() method is called. IsNull() This method gets a value indicating whether the specified column contains a null value. Working with a DataRow is a bit different from working with a DataColumn; you cannot create a direct instance of this type because there is no public constructor. // Error! No public constructor! DataRow r = new DataRow(); 867