Jan
09
A Quick Way to Copy a DataRow in C#
Filed Under (Development) by manatarms on 09-01-2009
This is fairly trivial. I just needed to remind myself of it. This can be found here.
1 2 3 4 5 6 7 8 | DataTable dtDest = new DataTable(); dtDest = dsActivity.Tables[0].Clone(); foreach(DataRow dr in dsSrc.Tables[0].Rows){ DataRow newRow = dtDest .NewRow(); newRow.ItemArray = dr.ItemArray; dtDest.Rows.Add(newRow); } |
If you’re copying all rows, why not just use:
DataTable dtDest = dsSrc.Tables[0].Copy();
In all honesty I’m not sure, but that seems that it would work just as well. Thanks for pointing that out.
This is exactly what I’m looking for. Thanks.
And it’s working fine.