Hi I have two datatable
table
id isfav 1 0 2 0 3 0 4 0 5 0
favtable
id 2 3
So I want to Update the table1 field isFav to 1 if the ids exist in FavTable.
Can anybody help me on this
Hi I have two datatable
id isfav 1 0 2 0 3 0 4 0 5 0
id 2 3
So I want to Update the table1 field isFav to 1 if the ids exist in FavTable.
Can anybody help me on this
Hari Prasad
On
Since in the comments it was mentioned it is DataTable, you could use Join between these tables as below and update the field.
table1.AsEnumerable()
.Join( table2.AsEnumerable(),
t1 => t1.Field<int>("id"),
t2 => t2.Field<int>("id"),
(t1, t2) => new { t1 })
.ToList()
.ForEach(o => o.t1["isfav"] = 1);
Check this working code
In SQL...
In Linq to SQL...
...or (more efficient)...