Solved

C# update one datatable from another datatable

Posted on 2014-01-17
2
2,079 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
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now