DataRow Class

 

Represents a row of data in a DataTable.

Namespace:   System.Data
Assembly:  System.Data (in System.Data.dll)

System.Object
  System.Data.DataRow

public class DataRow

NameDescription
System_CAPS_protmethodDataRow(DataRowBuilder)

This API supports the product infrastructure and is not intended to be used directly from your code. Initializes a new instance of the DataRow. Constructs a row from the builder. Only for internal usage..

NameDescription
System_CAPS_pubpropertyHasErrors

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

System_CAPS_pubpropertyItem[DataColumn]

Gets or sets the data stored in the specified DataColumn.

System_CAPS_pubpropertyItem[DataColumn, DataRowVersion]

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

System_CAPS_pubpropertyItem[Int32]

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

System_CAPS_pubpropertyItem[Int32, DataRowVersion]

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

System_CAPS_pubpropertyItem[String]

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

System_CAPS_pubpropertyItem[String, DataRowVersion]

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

System_CAPS_pubpropertyItemArray

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

System_CAPS_pubpropertyRowError

Gets or sets the custom error description for a row.

System_CAPS_pubpropertyRowState

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

System_CAPS_pubpropertyTable

Gets the DataTable for which this row has a schema.

NameDescription
System_CAPS_pubmethodAcceptChanges()

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

System_CAPS_pubmethodBeginEdit()

Starts an edit operation on a DataRow object.

System_CAPS_pubmethodCancelEdit()

Cancels the current edit on the row.

System_CAPS_pubmethodClearErrors()

Clears the errors for the row. This includes the RowError and errors set with SetColumnError.

System_CAPS_pubmethodDelete()

Deletes the DataRow.

System_CAPS_pubmethodEndEdit()

Ends the edit occurring on the row.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetChildRows(DataRelation)

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

System_CAPS_pubmethodGetChildRows(DataRelation, DataRowVersion)

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

System_CAPS_pubmethodGetChildRows(String)

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

System_CAPS_pubmethodGetChildRows(String, DataRowVersion)

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

System_CAPS_pubmethodGetColumnError(DataColumn)

Gets the error description of the specified DataColumn.

System_CAPS_pubmethodGetColumnError(Int32)

Gets the error description for the column specified by index.

System_CAPS_pubmethodGetColumnError(String)

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

System_CAPS_pubmethodGetColumnsInError()

Gets an array of columns that have errors.

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetParentRow(DataRelation)

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

System_CAPS_pubmethodGetParentRow(DataRelation, DataRowVersion)

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

System_CAPS_pubmethodGetParentRow(String)

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

System_CAPS_pubmethodGetParentRow(String, DataRowVersion)

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

System_CAPS_pubmethodGetParentRows(DataRelation)

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

System_CAPS_pubmethodGetParentRows(DataRelation, DataRowVersion)

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

System_CAPS_pubmethodGetParentRows(String)

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

System_CAPS_pubmethodGetParentRows(String, DataRowVersion)

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

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodHasVersion(DataRowVersion)

Gets a value that indicates whether a specified version exists.

System_CAPS_pubmethodIsNull(DataColumn)

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

System_CAPS_pubmethodIsNull(DataColumn, DataRowVersion)

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

System_CAPS_pubmethodIsNull(Int32)

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

System_CAPS_pubmethodIsNull(String)

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

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodRejectChanges()

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

System_CAPS_pubmethodSetAdded()

Changes the P:System.Data.DataRow.Rowstate of a DataRow to Added.

System_CAPS_pubmethodSetColumnError(DataColumn, String)

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

System_CAPS_pubmethodSetColumnError(Int32, String)

Sets the error description for a column specified by index.

System_CAPS_pubmethodSetColumnError(String, String)

Sets the error description for a column specified by name.

System_CAPS_pubmethodSetModified()

Changes the P:System.Data.DataRow.Rowstate of a DataRow to Modified.

System_CAPS_protmethodSetNull(DataColumn)

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

System_CAPS_pubmethodSetParentRow(DataRow)

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

System_CAPS_pubmethodSetParentRow(DataRow, DataRelation)

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

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubmethodField<T>(DataColumn)

Overloaded. Provides strongly-typed access to each of the column values in the specified row. The Field<T> method also supports nullable types. (Defined by DataRowExtensions.)

System_CAPS_pubmethodField<T>(DataColumn, DataRowVersion)

Overloaded. Provides strongly-typed access to each of the column values in the specified row. The Field<T> method also supports nullable types. (Defined by DataRowExtensions.)

System_CAPS_pubmethodField<T>(Int32)

Overloaded. Provides strongly-typed access to each of the column values in the specified row. The Field<T> method also supports nullable types. (Defined by DataRowExtensions.)

System_CAPS_pubmethodField<T>(Int32, DataRowVersion)

Overloaded. Provides strongly-typed access to each of the column values in the specified row. The Field<T> method also supports nullable types. (Defined by DataRowExtensions.)

System_CAPS_pubmethodField<T>(String)

Overloaded. Provides strongly-typed access to each of the column values in the specified row. The Field<T> method also supports nullable types. (Defined by DataRowExtensions.)

System_CAPS_pubmethodField<T>(String, DataRowVersion)

Overloaded. Provides strongly-typed access to each of the column values in the specified row. The Field<T> method also supports nullable types. (Defined by DataRowExtensions.)

System_CAPS_pubmethodSetField<T>(DataColumn, T)

Overloaded. Sets a new value for the specified column in the DataRow. The SetField<T> method also supports nullable types. (Defined by DataRowExtensions.)

System_CAPS_pubmethodSetField<T>(Int32, T)

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

System_CAPS_pubmethodSetField<T>(String, T)

Overloaded. Sets a new value for the specified column in the DataRow. The SetField<T> method also supports nullable types. (Defined by DataRowExtensions.)

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 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.

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;
}

.NET Framework
Available since 1.1

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

Return to top
Show: