Hi All
I want to merge Two Datatables to one
like this
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jisny AvRank #4,868 · 321 reputationPosted Sep 11, 2016, 8:23 PM EDT
table1.Columns.Add("M2");
table1.Columns.Add("M3");
DataRow row1 = table1.NewRow();
row1["M1"] = "100";
row1["M2"] = "120";
row1["M3"] = "322";
table1.Rows.Add(row1);
DataRow row2 = table1.NewRow();
row2["M1"] = "200";
row2["M2"] = "350";
row2["M3"] = "542";
table1.Rows.Add(row2);
DataRow row3 = table1.NewRow();
row3["M1"] = "300";
row3["M2"] = "120";
row3["M3"] = "544";
table1.Rows.Add(row3);
DataTable table2 = new DataTable();
table2.Columns.Add("ID");
table2.Columns.Add("Name_student");
DataRow row11 = table2.NewRow();
row11["ID"] = "1";
row11["Name_student"] = "Mohammed";
table2.Rows.Add(row11);
DataRow row22 = table2.NewRow();
row22["ID"] = "2";
row22["Name_student"] = "Ali";
table2.Rows.Add(row22);
DataRow row33 = table2.NewRow();
row33["ID"] = "3";
row33["Name_student"] = "Fahe";
table2.Rows.Add(row33);
DataTable table3 = new DataTable();
table3.Columns.Add("M1");
table3.Columns.Add("M2");
table3.Columns.Add("M3");
table3.Columns.Add("ID");
table3.Columns.Add("Name_student");
for (int i = 0; i < table1.Rows.Count; i++)
{
DataRow row111 = table3.NewRow();
row111["M1"] = table1.Rows[i]["M1"].ToString();
row111["M2"] = table1.Rows[i]["M2"].ToString();
row111["M3"] = table1.Rows[i]["M3"].ToString();
row111["ID"] = table2.Rows[i]["ID"].ToString();
row111["Name_student"] = table2.Rows[i]["Name_student"].ToString();
table3.Rows.Add(row111);
}
Midhun TpRank #388 · 6.5K reputationPosted Sep 2, 2016, 8:36 AM EDT
Please check below links-
http://www.c-sharpcorner.com/UploadFile/0c1bb2/merging-multiple-datatables-into-single-datatable-using-asp/
http://www.itdeveloperzone.com/2012/04/merge-2-datatables-in-c.html?m=1
Manas MohapatraRank #182 · 13.2K reputationPosted Sep 2, 2016, 9:00 AM EDT
lamasat lamasat55 reputationPosted Sep 2, 2016, 9:00 AM EDT
Midhun TpRank #388 · 6.5K reputationPosted Sep 2, 2016, 9:13 AM EDT
http://stackoverflow.com/questions/12278978/combining-n-datatables-into-a-single-datatable
Ramesh PalaniappanRank #370 · 6.8K reputationPosted Sep 10, 2016, 5:36 AM EDT
Bikesh SrivastavaRank #108 · 20.3K reputationPosted Sep 10, 2016, 11:56 AM EDT