Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C# update one datatable from another datatable

Posted on 2014-01-17
2
Medium Priority
?
2,727 Views
Last Modified: 2014-01-17
How do I update a field of one DataTable from another Datatable?

I have 2 Datatables

Datatable #1:
UPC
Quantity
Price
NewPrice

Datatable #2
UPC
NewPrice


I want to update DataTable #1 with the NewPrice column from Datatable #2 when the UPCs of the 2 tables match. I'm interested in the exact code (for statement?) that will generate the results.
0
Comment
Question by:esak2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 39787977
Assuming dt1 is the table to be updated and dt2 is where the new values are coming from - and that UPC is set as the primary key for both - you'd want something like:
foreach (DataRow row in dt2.Rows)
{
    dt1.Rows.Find(row["UPC"])["NewPrice"] = row["NewPrice"];
}

Open in new window

0
 

Author Comment

by:esak2000
ID: 39788198
nice and simple, thanks!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

636 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