none
C# DataSet question RRS feed

  • Question

  • Hello !

     

    I have a dataset filled with some database records.

    Now I want to go over each line and updating the cells with "new" information, though it's not quarenteed that the new value is different than the old one.

    Of course, setting the cell with any value, different or same, causes the row state to change, and thus when updating the database, I'm actually updating unneeded records.

     

    I've put in an if clause logic, but it's really looks like bad coding:

    if (cellOldValue != newValue)

    cellOldValue = newValue;

     

    Is there a better way of writing this kind of logic ?

    Friday, May 2, 2008 11:55 AM

Answers

  •  

    Hi

     

    the problem here is that once you assign a new value to a row, the row becomes RowState.Modified.

    So, in order for this not to happen you need to check before you assign a new value

    what you are doing is the correct way.  Did you do this type safe?

     

    Hope this helps you out

     

    F

    Friday, May 2, 2008 12:47 PM

All replies

  •  

    Hi

     

    the problem here is that once you assign a new value to a row, the row becomes RowState.Modified.

    So, in order for this not to happen you need to check before you assign a new value

    what you are doing is the correct way.  Did you do this type safe?

     

    Hope this helps you out

     

    F

    Friday, May 2, 2008 12:47 PM
  •  Johnny.YK wrote:

    Hello !

     

    I have a dataset filled with some database records.

    Now I want to go over each line and updating the cells with "new" information, though it's not quarenteed that the new value is different than the old one.

    Of course, setting the cell with any value, different or same, causes the row state to change, and thus when updating the database, I'm actually updating unneeded records.

     

    I've put in an if clause logic, but it's really looks like bad coding:

    if (cellOldValue != newValue)

    cellOldValue = newValue;

     

    Is there a better way of writing this kind of logic ?

     

    You can use Comparer class. I think this will be the best you can do. Or IComparer.Compare( Object x, Object y )

    Friday, May 2, 2008 1:17 PM
  • frederikm, thanks for the answer . I'll stay with that option, however Compare does look like an alternative .

     

    Thank you both :]

    Friday, May 2, 2008 5:20 PM