Difference between rows.add and importRow

前端 未结 2 1927
故里飘歌
故里飘歌 2021-01-17 20:50

When adding a row to a datatable in vb.net, what is the difference between rows.add and importRow?

Dim dt As DataTable
Dim dr As DataRow

\'Add row this way.         


        
2条回答
  •  醉酒成梦
    2021-01-17 21:07

    both do same functionality adding row to datatable but the main difference is

        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
    

    hope that will give you an idea..

提交回复
热议问题