Link to home
Start Free TrialLog in
Avatar of countrymeister
countrymeister

asked on

How to update a datatable field in linq to sql with a value from another datatable field

I tried this, but it does not update the values.

 dt1.Rows.Cast<DataRow>().Join(dt2.Rows.Cast<DataRow>(),
            r1 => new { p1 = r1["ID"], p2 = r1["Date"] },
            r2 => new { p1 = r2["ID"], p2 = r2["Date"] },
            (r1, r2) => new { r1, r2 }).ToList()
            .ForEach(o => o.r1.SetField("Price", o.r2["Price"]));
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

It looks like you are using a DataTable object and NOT Linq to SQL is that correct?
Avatar of countrymeister
countrymeister

ASKER

Yes, I have two datatables,
I need to update the values in dt1 if they qualify on the join in dt2
Sorry Fernando, I am using LINQ to SQL, nothing to do with database updates.
Just wanted to update certain rows in datatable on certain conditions
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My fields were not in the correct format, my fault