Changing data in a dataset

  • Thread starter Thread starter Ferdinand Zaubzer
  • Start date Start date
F

Ferdinand Zaubzer

I am trying to change a value in a Dataset but it doesn't work.

is there anything wrong with this code?

dataset.Tables[0].Rows[0].BeginEdit();
dataset.Tables[0].Rows[0].ItemArray[3] = "new Text";
dataset.Tables[0].Rows[0].EndEdit();

I have placed a breakpoint below those three lines, and when I debug the
application I can see that the value of
dataset.Tables[0].Rows[0].ItemArray[3] is not "new Text" but still the
old value.

Is there anything I could have forgotten?

Thanks
Ferdinand
 
Ferdinand,

You don't need to call BeginEdit and EndEdit.

The reason that you do not see the changes taking place is that
ItemArray returns a NEW object array with a copy of the values in the row.
You can just set the value directly, like so:

dataset.Tables[0].Rows[0][3] = "new Text";

And then the change will be reflected.

Hope this helps.
 
Back
Top