I have a dataset with multiple tables. One table in particular has one record in it. I am adding another record to this datatable and am using the Dataset.Copy() method to copy the entire dataset object to another instance.
Dataset2 = DirectCast(Dataset1.Copy(), dsApplication)
However, the new copy of the dataset returned from this method is not correct. The new row is there and has a RowState of "Added", but the value is blank (this is a string field). The dataset saves to the database with the blank value.
Now, I have two rows. The original one, and the blank one. If I change the blank one to have text and initiate the operation again, then the original dataset shows the row as having text, but with a RowState of Unchanged, and the second dataset again has blank for this row.
Does anyone have an explanation for this behavior? Why isn't the value of the second row being copied in the Dataset.Copy() operation? Why isn't the RowState of the second row showing as Modified after adding text?
Edit: The original dataset is being modified via a datagridview. If, after I type the text into the datagridview cell, I click onto another row before initiating the copy operation, it works fine. If I do not click onto another row, then it fails. Before I initiate the copy operation, I call the datagridview.endedit() method. It's still strange though because even without clicking onto another cell, when I debug the code, the original dataset always shows the correct value immediately before the copy operation, so I don't understand why the datagridview is having any affect at all.
Edit #2: While debugging, I noticed that if I change the first value in the gridview, the RowState gets changed to Modified, as expected. However, for any other row, the RowState remains as Unchanged despite the actual value changing.