DataRow DataRow DataRow DataRow Class

Definition

Represents a row of data in a DataTable.

public ref class DataRow
[Serializable]
public class DataRow
type DataRow = class
Public Class DataRow
Inheritance
DataRowDataRowDataRowDataRow
Attributes
SerializableAttribute

Examples

The following example creates a new DataRow by calling the NewRow method of the DataTable object.

private void CreateNewDataRow()
{
    // Use the MakeTable function below to create a new table.
    DataTable table;
    table = MakeNamesTable();

    // Once a table has been created, use the 
    // NewRow to create a DataRow.
    DataRow row;
    row = table.NewRow();

    // Then add the new row to the collection.
    row["fName"] = "John";
    row["lName"] = "Smith";
    table.Rows.Add(row);

    foreach(DataColumn column in table.Columns)
        Console.WriteLine(column.ColumnName);
    dataGrid1.DataSource=table;
}

private DataTable MakeNamesTable()
{
    // Create a new DataTable titled 'Names.'
    DataTable namesTable = new DataTable("Names"); 

    // Add three column objects to the table.
    DataColumn idColumn = new  DataColumn();
    idColumn.DataType = System.Type.GetType("System.Int32");
    idColumn.ColumnName = "id";
    idColumn.AutoIncrement = true;
    namesTable.Columns.Add(idColumn);

    DataColumn fNameColumn = new DataColumn();
    fNameColumn.DataType = System.Type.GetType("System.String");
    fNameColumn.ColumnName = "Fname";
    fNameColumn.DefaultValue = "Fname";
    namesTable.Columns.Add(fNameColumn);

    DataColumn lNameColumn = new DataColumn();
    lNameColumn.DataType = System.Type.GetType("System.String");
    lNameColumn.ColumnName = "LName";
    namesTable.Columns.Add(lNameColumn);

    // Create an array for DataColumn objects.
    DataColumn [] keys = new DataColumn [1];
    keys[0] = idColumn;
    namesTable.PrimaryKey = keys;

    // Return the new DataTable.
    return namesTable;
}
Private Sub CreateNewDataRow()
    ' Use the MakeTable function below to create a new table.
    Dim table As DataTable
    table = MakeNamesTable()

    ' Once a table has been created, use the 
    ' NewRow to create a DataRow.
    Dim row As DataRow 
    row = table.NewRow()

    ' Then add the new row to the collection.
    row("fName") = "John"
    row("lName") = "Smith"
    table.Rows.Add(row)
    
    Dim column As DataColumn
    For Each column in table.Columns
       Console.WriteLine(column.ColumnName)
    Next
    DataGrid1.DataSource=table
 End Sub
 
 Private Function MakeNamesTable() As DataTable
    ' Create a new DataTable titled 'Names.'
    Dim namesTable As DataTable = new DataTable("Names") 

    ' Add three column objects to the table.
    Dim idColumn As DataColumn = new  DataColumn()
    idColumn.DataType = System.Type.GetType("System.Int32")
    idColumn.ColumnName = "id"
    idColumn.AutoIncrement = True
    namesTable.Columns.Add(idColumn)

    Dim fNameColumn As DataColumn = New DataColumn()
    fNameColumn.DataType = System.Type.GetType("System.String")
    fNameColumn.ColumnName = "Fname"
    fNameColumn.DefaultValue = "Fname"
    namesTable.Columns.Add(fNameColumn)

    Dim lNameColumn As DataColumn = new DataColumn()
    lNameColumn.DataType = System.Type.GetType("System.String")
    lNameColumn.ColumnName = "LName"
    namesTable.Columns.Add(lNameColumn)

    ' Create an array for DataColumn objects.
    Dim keys(0) As DataColumn 
    keys(0) = idColumn
    namesTable.PrimaryKey = keys

    ' Return the new DataTable.
    MakeNamesTable = namesTable
 End Function

Remarks

The DataRow and DataColumn objects are primary components of a DataTable. Use the DataRow object and its properties and methods to retrieve and evaluate; and insert, delete, and update the values in the DataTable. The DataRowCollection represents the actual DataRow objects in the DataTable, and the DataColumnCollection contains the DataColumn objects that describe the schema of the DataTable. Use the overloaded Item[String, DataRowVersion] property to return or set the value of a DataColumn.

Use the HasVersion and IsNull properties to determine the status of a particular row value, and the RowState property to determine the state of the row relative to its parent DataTable.

To create a new DataRow, use the NewRow method of the DataTable object. After creating a new DataRow, use the Add method to add the new DataRow to the DataRowCollection. Finally, call the AcceptChanges method of the DataTable object to confirm the addition. For more information about adding data to a DataTable, see Adding Data to a DataTable.

You can delete a DataRow from the DataRowCollection by calling the Remove method of the DataRowCollection, or by calling the Delete method of the DataRow object. The Remove method removes the row from the collection. In contrast, Delete marks the DataRow for removal. The actual removal occurs when you call AcceptChanges method. By calling Delete, you can programmatically check which rows are marked for removal before actually deleting them. For more information, see DataRow Deletion.

Constructors

DataRow(DataRowBuilder) DataRow(DataRowBuilder) DataRow(DataRowBuilder) DataRow(DataRowBuilder)

Initializes a new instance of the DataRow. Constructs a row from the builder. Only for internal usage..

Properties

HasErrors HasErrors HasErrors HasErrors

Gets a value that indicates whether there are errors in a row.

ItemArray ItemArray ItemArray ItemArray

Gets or sets all the values for this row through an array.

Item[DataColumn, DataRowVersion] Item[DataColumn, DataRowVersion] Item[DataColumn, DataRowVersion] Item[DataColumn, DataRowVersion]

Gets the specified version of data stored in the specified DataColumn.

Item[DataColumn] Item[DataColumn] Item[DataColumn] Item[DataColumn]

Gets or sets the data stored in the specified DataColumn.

Item[Int32, DataRowVersion] Item[Int32, DataRowVersion] Item[Int32, DataRowVersion] Item[Int32, DataRowVersion]

Gets the data stored in the column, specified by index and version of the data to retrieve.

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

Gets or sets the data stored in the column specified by index.

Item[String, DataRowVersion] Item[String, DataRowVersion] Item[String, DataRowVersion] Item[String, DataRowVersion]

Gets the specified version of data stored in the named column.

Item[String] Item[String] Item[String] Item[String]

Gets or sets the data stored in the column specified by name.

RowError RowError RowError RowError

Gets or sets the custom error description for a row.

RowState RowState RowState RowState

Gets the current state of the row with regard to its relationship to the DataRowCollection.

Table Table Table Table

Gets the DataTable for which this row has a schema.

Methods

AcceptChanges() AcceptChanges() AcceptChanges() AcceptChanges()

Commits all the changes made to this row since the last time AcceptChanges() was called.

BeginEdit() BeginEdit() BeginEdit() BeginEdit()

Starts an edit operation on a DataRow object.

CancelEdit() CancelEdit() CancelEdit() CancelEdit()

Cancels the current edit on the row.

ClearErrors() ClearErrors() ClearErrors() ClearErrors()

Clears the errors for the row. This includes the RowError and errors set with SetColumnError(Int32, String).

Delete() Delete() Delete() Delete()

Deletes the DataRow.

EndEdit() EndEdit() EndEdit() EndEdit()

Ends the edit occurring on the row.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetChildRows(DataRelation) GetChildRows(DataRelation) GetChildRows(DataRelation) GetChildRows(DataRelation)

Gets the child rows of this DataRow using the specified DataRelation.

GetChildRows(DataRelation, DataRowVersion) GetChildRows(DataRelation, DataRowVersion) GetChildRows(DataRelation, DataRowVersion) GetChildRows(DataRelation, DataRowVersion)

Gets the child rows of a DataRow using the specified DataRelation, and DataRowVersion.

GetChildRows(String) GetChildRows(String) GetChildRows(String) GetChildRows(String)

Gets the child rows of a DataRow using the specified RelationName of a DataRelation.

GetChildRows(String, DataRowVersion) GetChildRows(String, DataRowVersion) GetChildRows(String, DataRowVersion) GetChildRows(String, DataRowVersion)

Gets the child rows of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.

GetColumnError(DataColumn) GetColumnError(DataColumn) GetColumnError(DataColumn) GetColumnError(DataColumn)

Gets the error description of the specified DataColumn.

GetColumnError(Int32) GetColumnError(Int32) GetColumnError(Int32) GetColumnError(Int32)

Gets the error description for the column specified by index.

GetColumnError(String) GetColumnError(String) GetColumnError(String) GetColumnError(String)

Gets the error description for a column, specified by name.

GetColumnsInError() GetColumnsInError() GetColumnsInError() GetColumnsInError()

Gets an array of columns that have errors.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetParentRow(DataRelation) GetParentRow(DataRelation) GetParentRow(DataRelation) GetParentRow(DataRelation)

Gets the parent row of a DataRow using the specified DataRelation.

GetParentRow(DataRelation, DataRowVersion) GetParentRow(DataRelation, DataRowVersion) GetParentRow(DataRelation, DataRowVersion) GetParentRow(DataRelation, DataRowVersion)

Gets the parent row of a DataRow using the specified DataRelation, and DataRowVersion.

GetParentRow(String) GetParentRow(String) GetParentRow(String) GetParentRow(String)

Gets the parent row of a DataRow using the specified RelationName of a DataRelation.

GetParentRow(String, DataRowVersion) GetParentRow(String, DataRowVersion) GetParentRow(String, DataRowVersion) GetParentRow(String, DataRowVersion)

Gets the parent row of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.

GetParentRows(DataRelation) GetParentRows(DataRelation) GetParentRows(DataRelation) GetParentRows(DataRelation)

Gets the parent rows of a DataRow using the specified DataRelation.

GetParentRows(DataRelation, DataRowVersion) GetParentRows(DataRelation, DataRowVersion) GetParentRows(DataRelation, DataRowVersion) GetParentRows(DataRelation, DataRowVersion)

Gets the parent rows of a DataRow using the specified DataRelation, and DataRowVersion.

GetParentRows(String) GetParentRows(String) GetParentRows(String) GetParentRows(String)

Gets the parent rows of a DataRow using the specified RelationName of a DataRelation.

GetParentRows(String, DataRowVersion) GetParentRows(String, DataRowVersion) GetParentRows(String, DataRowVersion) GetParentRows(String, DataRowVersion)

Gets the parent rows of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.

GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
HasVersion(DataRowVersion) HasVersion(DataRowVersion) HasVersion(DataRowVersion) HasVersion(DataRowVersion)

Gets a value that indicates whether a specified version exists.

IsNull(DataColumn) IsNull(DataColumn) IsNull(DataColumn) IsNull(DataColumn)

Gets a value that indicates whether the specified DataColumn contains a null value.

IsNull(DataColumn, DataRowVersion) IsNull(DataColumn, DataRowVersion) IsNull(DataColumn, DataRowVersion) IsNull(DataColumn, DataRowVersion)

Gets a value that indicates whether the specified DataColumn and DataRowVersion contains a null value.

IsNull(Int32) IsNull(Int32) IsNull(Int32) IsNull(Int32)

Gets a value that indicates whether the column at the specified index contains a null value.

IsNull(String) IsNull(String) IsNull(String) IsNull(String)

Gets a value that indicates whether the named column contains a null value.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
RejectChanges() RejectChanges() RejectChanges() RejectChanges()

Rejects all changes made to the row since AcceptChanges() was last called.

SetAdded() SetAdded() SetAdded() SetAdded()

Changes the RowState of a DataRow to Added.

SetColumnError(DataColumn, String) SetColumnError(DataColumn, String) SetColumnError(DataColumn, String) SetColumnError(DataColumn, String)

Sets the error description for a column specified as a DataColumn.

SetColumnError(Int32, String) SetColumnError(Int32, String) SetColumnError(Int32, String) SetColumnError(Int32, String)

Sets the error description for a column specified by index.

SetColumnError(String, String) SetColumnError(String, String) SetColumnError(String, String) SetColumnError(String, String)

Sets the error description for a column specified by name.

SetModified() SetModified() SetModified() SetModified()

Changes the RowState of a DataRow to Modified.

SetNull(DataColumn) SetNull(DataColumn) SetNull(DataColumn) SetNull(DataColumn)

Sets the value of the specified DataColumn to a null value.

SetParentRow(DataRow) SetParentRow(DataRow) SetParentRow(DataRow) SetParentRow(DataRow)

Sets the parent row of a DataRow with specified new parent DataRow.

SetParentRow(DataRow, DataRelation) SetParentRow(DataRow, DataRelation) SetParentRow(DataRow, DataRelation) SetParentRow(DataRow, DataRelation)

Sets the parent row of a DataRow with specified new parent DataRow and DataRelation.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Extension Methods

Field<T>(DataRow, DataColumn) Field<T>(DataRow, DataColumn) Field<T>(DataRow, DataColumn) Field<T>(DataRow, DataColumn)

Provides strongly-typed access to each of the column values in the specified row. The Field<T>(DataRow, DataColumn) method also supports nullable types.

Field<T>(DataRow, DataColumn, DataRowVersion) Field<T>(DataRow, DataColumn, DataRowVersion) Field<T>(DataRow, DataColumn, DataRowVersion) Field<T>(DataRow, DataColumn, DataRowVersion)

Provides strongly-typed access to each of the column values in the specified row. The Field<T>(DataRow, DataColumn, DataRowVersion) method also supports nullable types.

Field<T>(DataRow, Int32) Field<T>(DataRow, Int32) Field<T>(DataRow, Int32) Field<T>(DataRow, Int32)

Provides strongly-typed access to each of the column values in the specified row. The Field<T>(DataRow, Int32) method also supports nullable types.

Field<T>(DataRow, Int32, DataRowVersion) Field<T>(DataRow, Int32, DataRowVersion) Field<T>(DataRow, Int32, DataRowVersion) Field<T>(DataRow, Int32, DataRowVersion)

Provides strongly-typed access to each of the column values in the specified row. The Field<T>(DataRow, Int32, DataRowVersion) method also supports nullable types.

Field<T>(DataRow, String) Field<T>(DataRow, String) Field<T>(DataRow, String) Field<T>(DataRow, String)

Provides strongly-typed access to each of the column values in the specified row. The Field<T>(DataRow, String) method also supports nullable types.

Field<T>(DataRow, String, DataRowVersion) Field<T>(DataRow, String, DataRowVersion) Field<T>(DataRow, String, DataRowVersion) Field<T>(DataRow, String, DataRowVersion)

Provides strongly-typed access to each of the column values in the specified row. The Field<T>(DataRow, String, DataRowVersion) method also supports nullable types.

SetField<T>(DataRow, DataColumn, T) SetField<T>(DataRow, DataColumn, T) SetField<T>(DataRow, DataColumn, T) SetField<T>(DataRow, DataColumn, T)

Sets a new value for the specified column in the DataRow. The SetField<T>(DataRow, DataColumn, T) method also supports nullable types.

SetField<T>(DataRow, Int32, T) SetField<T>(DataRow, Int32, T) SetField<T>(DataRow, Int32, T) SetField<T>(DataRow, Int32, T)

Sets a new value for the specified column in the DataRow the method is called on. The SetField<T>(DataRow, Int32, T) method also supports nullable types.

SetField<T>(DataRow, String, T) SetField<T>(DataRow, String, T) SetField<T>(DataRow, String, T) SetField<T>(DataRow, String, T)

Sets a new value for the specified column in the DataRow. The SetField<T>(DataRow, String, T) method also supports nullable types.

Applies to

Thread Safety

This type is safe for multithreaded read operations. You must synchronize any write operations.

See Also