Changing data in a dataset

  • Thread starter Ferdinand Zaubzer
  • 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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top