I have a dataset with two datatables dt1 and dt2, dt1 have one row and dt2 have more than one rows,. Both the data tables have colums[BILLNO], I want to add all the rows of dt2 to dt1, if dt1 does not contain that bill no which exists in dt2. Please help me to loop through the tables and add those table rows to other table. If anyone have any suggested links please specify. Thank you.
Data Sets and data tables in c#
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Sachin SinghRank #66 · 26.2K reputationPosted Aug 13, 2021, 3:57 PM EDT
Ganesan CRank #369 · 6.8K reputationPosted Aug 14, 2021, 12:07 PM EDT
Hi,
If your both two tables has same primary key then simply merge as follows,
DataTable dt = dt1.Merge(dt2);
Otherwise you can use as follows,
foreach (DataRow r in dt2.Rows ) { if (!dt1.Rows.Contains(r["id"])) { dt1.ImportRow(r); } }