vb.net – rows.add和importRow之间的区别

前端之家收集整理的这篇文章主要介绍了vb.net – rows.add和importRow之间的区别前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在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但主要区别是
DataTable 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

希望能给你一个想法..

猜你在找的VB相关文章