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

Posted on 2013-10-02
Medium Priority
Last Modified: 2016-02-10
I tried this, but it does not update the values.

            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"]));
Question by:countrymeister
  • 3
  • 2
LVL 64

Expert Comment

by:Fernando Soto
ID: 39542009
It looks like you are using a DataTable object and NOT Linq to SQL is that correct?

Author Comment

ID: 39542133
Yes, I have two datatables,
I need to update the values in dt1 if they qualify on the join in dt2

Author Comment

ID: 39542969
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
LVL 64

Accepted Solution

Fernando Soto earned 2000 total points
ID: 39543532
I have tested your code and find it to work as expected. The Price column of DataTable 2 updates the Price column of DataTable 1.

What are you looking at when you say it is not working?

Author Comment

ID: 39564057
My fields were not in the correct format, my fault

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
SingleRun is a tool that ensures that only one instance of an application is started, running it again brings the application to focus.
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
Through the video, you can check the migration process of Outlook PST file to PDF. Kernel for Outlook to PDF tool can convert Outlook emails with all attributes like Subject, To, From, Cc, Bcc and other folders such as Inbox, Outbox, Sent Items, Jun…

587 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question