Bienvenido Omosura
Bienvenido Omosura

Reputation: 127

Changing the Rows state in DataTable if it meets the following condition

i have two tables: DataTable dt_o; and DataTable dt_m;

Contents of dt_m:

ID        |    Name      |    Age    
--------------------------------------
08        |    Farel     |     18      
07        |    Ema       |     18
10        |    Sophie    |     19
11        |    Cyril     |     12

Contents of dt_o:

ID        |    Name      |    Age    
--------------------------------------
08        |    Farel     |     19      
07        |    Ema       |     18
10        |    Sophie    |     19

the row from dt_m with the ID of 08 should be set to row.SetModified() since once of it's columns value where different in the other Table[dt_o]

and the row from dt_m with the ID of 11 should be set to row.SetAdded() since it doesn't exist in the other table...

and the rest of the row, there row states would be set to unchange state..

any code suggestion?

Upvotes: 0

Views: 341

Answers (1)

Ben Holland
Ben Holland

Reputation: 341

I would search the tables for the specified requirements you're seeking using the answer of this post: how to search the dataset for specific data

Then just set the state of the rows returned based on what you wanna do. For example:

dataSet.AcceptChanges(); //If you'd like to start with everything as "unchanged"

foreach(DataRow row in rowsReturnedFromQuery1)
    row.SetAdded();

foreach(DataRow row2 in rowsReturnedFromQuery2)
    row2.SetModified();

Hope this helps. I'm sure you can do this using Linq as well.

Upvotes: 1

Related Questions