DataRow DataRow DataRow DataRow Class

定义

表示 DataTable 中的一行数据。Represents a row of data in a DataTable.

public ref class DataRow
[System.Serializable]
public class DataRow
type DataRow = class
Public Class DataRow
继承
DataRowDataRowDataRowDataRow
属性

示例

下面的示例创建一个新DataRow通过调用NewRow方法的DataTable对象。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

注解

DataRowDataColumn对象是主要组件DataTableThe DataRow and DataColumn objects are primary components of a DataTable. 使用DataRow对象及其属性和方法来检索和评估; 以及插入、 删除和更新中的值DataTableUse the DataRow object and its properties and methods to retrieve and evaluate; and insert, delete, and update the values in the DataTable. DataRowCollection表示的实际DataRow中的对象DataTable,和DataColumnCollection包含DataColumn描述的架构的对象DataTableThe DataRowCollection represents the actual DataRow objects in the DataTable, and the DataColumnCollection contains the DataColumn objects that describe the schema of the DataTable. 使用重载Item[String, DataRowVersion]属性来返回或设置的值DataColumnUse the overloaded Item[String, DataRowVersion] property to return or set the value of a DataColumn.

使用HasVersionIsNull属性来确定特定行值的状态并RowState属性来确定相对于其父行的状态DataTableUse 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.

若要创建一个新DataRow,使用NewRow方法的DataTable对象。To create a new DataRow, use the NewRow method of the DataTable object. 创建一个新后DataRow,使用Add方法以添加新DataRowDataRowCollectionAfter creating a new DataRow, use the Add method to add the new DataRow to the DataRowCollection. 最后,调用AcceptChanges方法的DataTable以确认添加的对象。Finally, call the AcceptChanges method of the DataTable object to confirm the addition. 有关将数据添加到详细信息DataTable,请参阅将数据添加到 DataTableFor more information about adding data to a DataTable, see Adding Data to a DataTable.

可以删除DataRowDataRowCollection通过调用Remove方法DataRowCollection,或通过调用Delete方法DataRow对象。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. Remove方法从集合中删除行。The Remove method removes the row from the collection. 与此相反,Delete标记DataRow删除。In contrast, Delete marks the DataRow for removal. 在调用时,会发生实际移除AcceptChanges方法。The actual removal occurs when you call AcceptChanges method. 通过调用Delete,可以通过编程方式检查哪些行标记为删除前实际删除它们。By calling Delete, you can programmatically check which rows are marked for removal before actually deleting them. 有关详细信息,请参阅DataRow 删除For more information, see DataRow Deletion.

构造函数

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

初始化 DataRow 的新实例。Initializes a new instance of the DataRow. 从生成器中构造行。Constructs a row from the builder. 仅限内部使用。Only for internal usage.

属性

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]

获取指定 DataColumn 中存储的数据的指定版本。Gets the specified version of data stored in the specified DataColumn.

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

获取或设置指定 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

获取与该行和 DataRowCollection 的关系相关的当前状态。Gets the current state of the row with regard to its relationship to the DataRowCollection.

Table Table Table Table

获取该行拥有其架构的 DataTableGets the DataTable for which this row has a schema.

方法

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

提交自上次调用 AcceptChanges() 以来对该行进行的所有更改。Commits all the changes made to this row since the last time AcceptChanges() was called.

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

DataRow 对象启动编辑操作。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. 这包括 RowErrorSetColumnError(Int32, String) 的错误设置。This includes the RowError and errors set with SetColumnError(Int32, String).

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

删除 DataRowDeletes 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)

使用指定的 DataRelation 获取此 DataRow 的子行。Gets the child rows of this DataRow using the specified DataRelation.

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

使用指定的 DataRelationDataRowVersion 获取 DataRow 的子行。Gets the child rows of a DataRow using the specified DataRelation, and DataRowVersion.

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

使用 DataRelation 的指定 RelationName 获取 DataRow 的子行。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)

使用 DataRelation 的指定 RelationNameDataRowVersion获取 DataRow 的子行。Gets the child rows of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.

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

获取指定 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)

使用指定的 DataRelation 获取 DataRow 的父行。Gets the parent row of a DataRow using the specified DataRelation.

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

使用指定的 DataRelationDataRowVersion 获取 DataRow 的父行。Gets the parent row of a DataRow using the specified DataRelation, and DataRowVersion.

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

使用 DataRelation 的指定 RelationName 获取 DataRow 的父行。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)

使用 DataRelation 的指定 RelationNameDataRowVersion 获取 DataRow 的父行。Gets the parent row of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.

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

使用指定的 DataRelation 获取 DataRow 的父行。Gets the parent rows of a DataRow using the specified DataRelation.

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

使用指定的 DataRelationDataRowVersion 获取 DataRow 的父行。Gets the parent rows of a DataRow using the specified DataRelation, and DataRowVersion.

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

使用 DataRelation 的指定 RelationName 获取 DataRow 的父行。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)

使用 DataRelation 的指定 RelationNameDataRowVersion 获取 DataRow 的父行。Gets the parent rows of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.

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

获取当前实例的 TypeGets 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)

获取一个值,该值指示指定的 DataColumn 是否包含 null 值。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)

获取一个值,该值指示指定的 DataColumnDataRowVersion 是否包含 null 值。Gets a value that indicates whether the specified DataColumn and DataRowVersion contains a null value.

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

获取一个值,该值指示位于指定索引处的列是否包含 null 值。Gets a value that indicates whether the column at the specified index contains a null value.

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

获取一个值,该值指示指定的列是否包含 null 值。Gets a value that indicates whether the named column contains a null value.

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

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

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

拒绝自上次调用 AcceptChanges() 以来进行的所有更改。Rejects all changes made to the row since AcceptChanges() was last called.

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

DataRowRowState 更改为 AddedChanges the RowState of a DataRow to Added.

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

为指定为 DataColumn 的列设置错误说明。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()

DataRowRowState 更改为 ModifiedChanges the RowState of a DataRow to Modified.

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

将指定 DataColumn 的值设置为 null 值。Sets the value of the specified DataColumn to a null value.

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

使用指定的新父 DataRow 设置 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)

使用指定的新父 DataRowDataRelation 设置 DataRow 的父行。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)

扩展方法

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. Field<T>(DataRow, DataColumn) 方法还支持可以为 null 的类型。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. Field<T>(DataRow, DataColumn, DataRowVersion) 方法还支持可以为 null 的类型。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. Field<T>(DataRow, Int32) 方法还支持可以为 null 的类型。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. Field<T>(DataRow, Int32, DataRowVersion) 方法还支持可以为 null 的类型。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. Field<T>(DataRow, String) 方法还支持可以为 null 的类型。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. Field<T>(DataRow, String, DataRowVersion) 方法还支持可以为 null 的类型。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)

DataRow 中的指定列设置一个新值。Sets a new value for the specified column in the DataRow. SetField<T>(DataRow, DataColumn, T) 方法还支持可以为 null 的类型。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)

为在其上调用此方法的 DataRow 中的指定列设置一个新值。Sets a new value for the specified column in the DataRow the method is called on. SetField<T>(DataRow, Int32, T) 方法还支持可以为 null 的类型。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)

DataRow 中的指定列设置一个新值。Sets a new value for the specified column in the DataRow. SetField<T>(DataRow, String, T) 方法还支持可以为 null 的类型。The SetField<T>(DataRow, String, T) method also supports nullable types.

适用于

线程安全性

此类型是安全的多线程读取操作。This type is safe for multithreaded read operations. 你必须同步的任何写入操作。You must synchronize any write operations.

另请参阅