Merge 2 DataTables and store in a new one

后端 未结 5 1888
别那么骄傲
别那么骄傲 2020-11-28 11:14

If I have 2 DataTables (dtOne and dtTwo) and I want to merge them and put them in another DataTable (dtAll). How can I do this in C#? I tried the Merge statement on the da

5条回答
  •  余生分开走
    2020-11-28 11:46

    This is what i did for merging two datatables and bind the final result to the gridview

            DataTable dtTemp=new DataTable();
            for (int k = 0; k < GridView2.Rows.Count; k++)
            {
                string roomno = GridView2.Rows[k].Cells[1].Text;
                DataTable dtx = GetRoomDetails(chk, roomno, out msg);
                if (dtx.Rows.Count > 0)
                {
                    dtTemp.Merge(dtx);
                    dtTemp.AcceptChanges();
    
                }
            }
    

提交回复
热议问题