none
SteValue method does not work. RRS feed

  • Question

  • It is very frustrating to find out after hours of development that a method used so widely does not work as intended. Is it supposed to modify values in a DataRow or not? What is the meaning of .SetValue semantically?

    I find that if I have DataRow[] dtRows and want to modify some values in the fields the only way to do it is to use

    foreach (DataRow row in dtRows)

    row[0] = someValue;

    If I try:

    dtRows[0].ItemArray.SetValue (someValue, 0);

    it won't work. it compiles, execution takes place but the values remain unchanged. Am I missing something?

    Thanks.

    Wednesday, December 13, 2006 6:30 PM

All replies

  • The problem is the 0 in setvalue. The value needs to increment, for example:

     

    dtRows[0].ItemArray.SetValue ("Test1", 0);

    dtRows[0].ItemArray.SetValue ("Test1", 1);

    dtRows[0].ItemArray.SetValue ("Test1", 2);

    dtRows[0].ItemArray.SetValue ("Test1", 3);

     

    Best regards,

    Craig Maslowski MCT

    Wednesday, December 13, 2006 6:39 PM
  • I know the topic is old, but for those who are still searching you can use a double indexer like this

    dtRows[i][j] = value;

    Hope this helps some one.
    Thursday, October 16, 2008 4:30 PM
  • ionutnespus said:

    I know the topic is old, but for those who are still searching you can use a double indexer like this

    dtRows[i][j] = value;

    Hope this helps some one.

    It is a cute idea. There is a chance that I have used it somewhere in my code already but right now it would be hard to find. It is really a great shorthand.


    AlexB
    Thursday, October 16, 2008 5:21 PM