Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Copy specific rows from one Datatable to another

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.72k
    Comment on it

    Copy only columns from a datatable

    Use 'clone' method to create a datatable with same structure

     dtCopyColumns= dt.Clone();
    

    This will copy only columns from dt to dtCopyColumns


    Copy columns and rows from a datatable

       dtCopy =   dt.Copy();
    

    This will copy structure as well as data from dt to dtCopy

    Copy selected rows from one datatable to another

    To get selected rows from one datatable first create the structure, select rows, copy the rows

    dtSelectedRows = dt.Clone();
    DataRow[] dr1 = dt.Select("Name = '" + name + "'");
    // use your criteria to select rows
    foreach (DataRow row1 in dr1)
        {
             dtSelectedRows.ImportRow(row1);
        }
    

 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: