DataTable.ImportRow(DataRow) 方法

定义

DataRow 复制到 DataTable 中,保留任何属性设置以及初始值和当前值。Copies a DataRow into a DataTable, preserving any property settings, as well as original and current values.

public:
 void ImportRow(System::Data::DataRow ^ row);
public void ImportRow (System.Data.DataRow row);
member this.ImportRow : System.Data.DataRow -> unit
Public Sub ImportRow (row As DataRow)

参数

row
DataRow

要导入的 DataRowThe DataRow to be imported.

注解

调用 NewRow 使用现有的表架构将行添加到表中,但对于行使用默认值,并将设置 DataRowStateDetachedCalling NewRow adds a row to the table using the existing table schema, but with default values for the row, and sets the DataRowState to Detached. 调用 ImportRow 将保留现有的 DataRowState 和行中的其他值。Calling ImportRow preserves the existing DataRowState along with other values in the row. 如果 DataRow 作为参数传递的处于已分离状态,则将其忽略,并且不会引发异常。If the DataRow that is passed as a parameter is in a detached state, it is ignored, and no exception is thrown.

新行将添加到数据表的末尾。The new row will be added to the end of the data table.

如果新行违反约束,则不会将其添加到数据表。If the new row violates a Constraint it won't be added to the data table.

可以获取新行的索引,其形式为 DataTable. IndexOf 和 DataTable。You can get the index of the new row with as DataTable.Rows.Find and DataTable.Rows.IndexOf. 有关更多信息,请参见DataRowCollectionRowsSee DataRowCollection and Rows for more information.

适用于

另请参阅