Name
DataRow
Synopsis
The DataRow
class represents a single record in a
database. You can access the columns of the record using the indexer,
which is also the indexer for the class. You can retrieve or set a
column value using a zero-based index or the column name. Using the
name is slightly slower because it requires a behind-the-scenes
hashtable lookup. The indexer has two overloads that allow you to
specify the row version to retrieve using the
DataRowVersion
enumeration. For example:
Console.Write(row["ID"], DataRowVersion.Original);
retrieves the original data source value, even if it has been
modified. If you omit the version, you receive the current
(DataRowVersion.Current
) value.
Alternatively, you can get or set values for all the rows at one time
using the ItemArray
property. The
ItemArray
is a one-dimensional array, in which
each item contains the value for a field, in the same order as the
DataRow
. The ItemArray
doesn’t include the names of the field. You can also
retrieve the state of the row (indicating if it has been added,
deleted, and so on), using the RowState
property.
The DataRow
allocates space for error information.
You can set or retrieve a string that describes an error using the
SetColumnError( )
or GetColumnError( )
methods. To determine if the row has any errors, simply
inspect the Boolean HasErrors
property or retrieve
the DataColumn
objects with errors using the
GetColumnsInError( )
method.
The GetParentRow( )
and GetChildRows( )
methods allow you to retrieve ...
Get ADO.NET in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.