在vb.net中向数据表添加行时,rows.add和importRow之间有什么区别?
Dim dt As DataTable Dim dr As DataRow 'Add row this way... dt.rows.add(dr) 'or this way. dt.importRow(dr)
两者都做相同的功能添加行到datatable但主要区别是
原文链接:https://www.f2er.com/vb/255508.htmlDataTable dt1=new DataTable(); DataRow dr1=dt1.NewRow(); DataTable dt2=new DataTable(); dt2.Rows.Add(dr1); // will give you error already dr1 belongs to another datatable in that //case you can do like this dt2.ImportRow(dr1); // safe dt1.Rows.Add(dr1); // safe as dr1 Row belongs to DataTable1 so no exception raise
希望能给你一个想法..