Trying to create separate instance of DataSet, but I can't separate them
I have a DataSet called Apples. I need to massage the data table in there so that I can add blank row and a couple other rows. These rows need to be added because I am binding to a ComboBox.
I do not want to add these as rows to my actual DataSet, so I want to create a copy of it and bind my ComboBox to the copy. Problem is, whenever I try and create a copy it's like it's a reference and anything I开发者_JAVA百科 add to the "copy" ends up in the original.
Here is my syntax, is there any way to get a true separate object? Thanks!
Apples.Apple apples = new Apples.Apple();
apples.ReadXml("C:\apples.xml");
DataTable dt = new DataTable();
dt = apples.Apple;
Now if I add rows to 'dt', they also show up in "apples.Apple! How can I get around that?
Try dt = apples.Apple.Copy();
, assuming Apple
is a DataTable.
Edit: Copy, not clone.
精彩评论