Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#DataTable:ImportRow(DataRow)与Rows.Add(DataRow.ItemArray)的比较_C#_Asp.net_Datatable_Datarow - Fatal编程技术网

C#DataTable:ImportRow(DataRow)与Rows.Add(DataRow.ItemArray)的比较

C#DataTable:ImportRow(DataRow)与Rows.Add(DataRow.ItemArray)的比较,c#,asp.net,datatable,datarow,C#,Asp.net,Datatable,Datarow,我有两个具有相同模式的DataTable: DataTable t1 = new DataTable(); DataTable t2 = t1.Clone(); 如果我想向t1添加新的DataRow: DataRow row=t1.NewRow(); t1.Rows.Add(t1); 我不能使用t1.ImportRow(行)由于创建后,行处于分离状态,因此它将被ImportRow方法忽略(请参阅) 现在我想将行复制到t2:我知道数据行对象只能包含在一个数据表中,因此需要创建一个副本,要做到这

我有两个具有相同模式的
DataTable

DataTable t1 = new DataTable();
DataTable t2 = t1.Clone();
如果我想向
t1
添加新的
DataRow

DataRow row=t1.NewRow();
t1.Rows.Add(t1);
我不能使用
t1.ImportRow(行)由于创建后,
处于分离状态,因此它将被
ImportRow
方法忽略(请参阅)

现在我想将
复制到
t2
:我知道
数据行
对象只能包含在一个
数据表
中,因此需要创建一个副本,要做到这一点,可以使用两种方法:

t1.Rows.Add(row.ItemArray);


我的问题是:are
t1.Rows.Add(row.ItemArray)
t1.ImportRow(行)等效?我所有的假设都正确吗?

我已经研究了代码,它看起来像是
t1.Rows.Add(row.ItemArray)

就不会那么复杂了。无论如何,这些方法在技术上并不等同。

你说的“技术上不等同”是什么意思?它们有不同的副作用或结果吗?@WoDoSc它们实际上有不同的代码,导入方法进行额外的检查等。
t1.ImportRow(row);