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 New DataTable("Names") 

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

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

    Dim lNameColumn As 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

備註

和物件是的主要元件。 DataTable DataRow DataColumnThe DataRow and DataColumn objects are primary components of a DataTable. 使用物件及其屬性和方法來抓取和評估, 並DataTable在中插入、刪除和更新值。 DataRowUse the DataRow object and its properties and methods to retrieve and evaluate; and insert, delete, and update the values in the DataTable. DataRowCollection代表中的實際DataRow物件DataColumn DataTable, 而包含描述架構的物件。 DataColumnCollection DataTableThe DataRowCollection represents the actual DataRow objects in the DataTable, and the DataColumnCollection contains the DataColumn objects that describe the schema of the DataTable. 使用多DataColumn載屬性來傳回或Item[String, DataRowVersion]設定的值。Use the overloaded Item[String, DataRowVersion] property to return or set the value of a DataColumn.

您可以使用IsNull和屬性來判斷特定資料RowState列值的狀態, 以及用來判斷資料列相對於其父系DataTable之狀態的屬性。 HasVersionUse 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.

您可以藉DataRowCollectionDataRow Remove 呼叫的Delete方法DataRow , 或呼叫物件的方法, 從刪除。 DataRowCollectionYou 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 之關聯性 (Relationship) 的資料列目前狀態。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. 這包括 RowError 和以 SetColumnError(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)

使用指定的 DataRow,取得這個 DataRelation 的子資料列。Gets the child rows of this DataRow using the specified DataRelation.

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

使用指定的 DataRowDataRelation,取得 DataRowVersion 的子資料列。Gets the child rows of a DataRow using the specified DataRelation, and DataRowVersion.

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

使用 DataRow 的指定 RelationName,取得 DataRelation 的子資料列。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)

使用 DataRow 的指定 RelationNameDataRelation,取得 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)

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

使用指定的 DataRow,取得 DataRelation 的父資料列。Gets the parent row of a DataRow using the specified DataRelation.

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

使用指定的 DataRowDataRelation,取得 DataRowVersion 的父資料列。Gets the parent row of a DataRow using the specified DataRelation, and DataRowVersion.

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

使用 DataRow 的指定 RelationName,取得 DataRelation 的父資料列。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)

使用 DataRow 的指定 RelationNameDataRelation,取得 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)

使用指定的 DataRow,取得 DataRelation 的父資料列。Gets the parent rows of a DataRow using the specified DataRelation.

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

使用指定的 DataRowDataRelation,取得 DataRowVersion 的父資料列。Gets the parent rows of a DataRow using the specified DataRelation, and DataRowVersion.

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

使用 DataRow 的指定 RelationName,取得 DataRelation 的父資料列。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)

使用 DataRow 的指定 RelationNameDataRelation,取得 DataRowVersion 的父資料列。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 的淺層複本 (Shallow Copy)。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()

RowStateDataRow 變更為 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()

RowStateDataRow 變更為 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)

使用指定的新父 DataRowDataRow,設定 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)

擴充方法

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.

另請參閱