2

I want to change a Datarow value. I want to change DT2[0].ItemArray[3] I tried this code, but it didn't work.

private void Func(DataRow[] DtRowTemp)
{
    DataRow[] DT2 ;
    DT2 = DtRowTemp; // It work and DTRowTemp value has set to DT2

    // above code don't work
    DT2[0].ItemArray[3] = 3;   // Last Value Was 2 and I want to change this value to 3
}
Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Masoud Abasian
  • 10,549
  • 6
  • 23
  • 22

1 Answers1

7

With the ItemArray Property you get or set the ENTIRE array, not a single value.

Use this to set the fourth item:

 DT2[0][3] = 3;
Emond
  • 50,210
  • 11
  • 84
  • 115
  • @shf301, Indeed. Thanks, I'll add it to the answer. – Emond Jul 30 '11 at 20:13
  • Thanks for your help this is working for me. However it doesn't seem to be saving the set value I give it, how do I do persist the new value? thanks – Sambuxc Jan 04 '15 at 15:02
  • @Samuroid - What do you mean by persist? Save it in a file or database? – Emond Jan 04 '15 at 15:19
  • I have actually got it working now, I thought it was resetting back to the previous value but it isn't, thanks though @ErnodeWeerd – Sambuxc Jan 04 '15 at 15:31
  • Trying to reference `Item` is an error in Visual Studio, the second syntax isn't just shorter, it's required: http://stackoverflow.com/questions/7873972/in-c-why-no-item-on-system-data-datarow – DCShannon Sep 08 '15 at 16:45
  • And I just got crazy why the hell its so hard to set a simple value to a cell compared to my `DataGridView`. Thanks for this, very helpful. – C4d Feb 15 '16 at 16:11