B
Bruce Schechter
I fear that I am asking a very elementary question, but never-the-less I
need help so here goes...
I need to simply copy the contents of one DataTable into another DataTable.
My application looks something like this....
DataTable dt1, dt2;
dt1 = new DataTable();
// Read dt1 from database
....
// Here is where I need help... I need to copy the contents of dt1 into
dt2.
// Then, ...do some drastic manipulation of dt2 but need to keep the
original content within dt1.
DataView dv = new DataView( dt2 );
DataGrid.DataSource = dv;
.... etc.
As for how to copy the DataTable, I found the MemberwiseClone() method, but
it turns out to be "protected" so I get a compiler error when I try to use
it. Is there a way to use it? Or, is there a better way?
Also, note that I don't want to do a crude copy solution like iterating
through all the rows and elements to re-create dt2, because I don't want to
lose all the excellent "metadata" (like column names, types, etc.) that
ADO.NET so cleverly binds into a DataTable read from a database.
I'm new to the .NET game, so forgive me if I'm missing some obvious points.
Cheers, Bruce
need help so here goes...
I need to simply copy the contents of one DataTable into another DataTable.
My application looks something like this....
DataTable dt1, dt2;
dt1 = new DataTable();
// Read dt1 from database
....
// Here is where I need help... I need to copy the contents of dt1 into
dt2.
// Then, ...do some drastic manipulation of dt2 but need to keep the
original content within dt1.
DataView dv = new DataView( dt2 );
DataGrid.DataSource = dv;
.... etc.
As for how to copy the DataTable, I found the MemberwiseClone() method, but
it turns out to be "protected" so I get a compiler error when I try to use
it. Is there a way to use it? Or, is there a better way?
Also, note that I don't want to do a crude copy solution like iterating
through all the rows and elements to re-create dt2, because I don't want to
lose all the excellent "metadata" (like column names, types, etc.) that
ADO.NET so cleverly binds into a DataTable read from a database.
I'm new to the .NET game, so forgive me if I'm missing some obvious points.
Cheers, Bruce