Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Difference between DataTable.Rows.Add(DataRow) and DataTable.ImportRow(DataRow)?

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 4.79k
    Comment on it

    Hello Reader ,

    When adding a row to DataTable, there are two methods available in C# and VB.Net i.e.


    DataTable.Rows.Add(DataRow) and DataTable.ImportRow(DataRow). Both do the same functionality, adding a row to DataTable but the main difference is that if you want to make a new row in table you can use Row.Add() but if you want to import row from another table you can use ImportRow().


    So ImportRow is basically used for using another row from different table. For example -

    DataTable dtFirst = new DataTable();
    DataTable dtSecond = new DataTable();
    
    DataRow drFirst = dtFirst.NewRow();
    
    dtSecond.Rows.Add(drFirst);
    // Above line will give you error already drFirst belongs to another DataTable 
    // in that case you can do like this
    dtSecond.ImportRow(drFirst); 
    
    dtFirst.Rows.Add(drFirst); 
    // Above line is safe as drFirst Row belongs to dtFirst DataTable 
    // so no exception will raise.
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: