Breaking News

Editors Picks

Wednesday, April 6, 2011

Combine Two DataTables Into One Datatable


How to combine two datatables into single datatable - C# 





public void getgroupRecentActivity()
        {
            DataTable dtjoingroup =   Group.GetAllGroupDetailbydate(Request.QueryString["GroupID"]);
            DataTable dtcreateGroupForum = Group.GetAllGroupForumDetailbydate(Request.QueryString["GroupID"]);
            DataSet dsjoin1 = new DataSet();
            DataSet dsjoin2 = new DataSet();        
            foreach (DataRow dr in dtjoingroup.Rows)
            {
                dr["GroupName"] = "commented on the forum";
                dr.AcceptChanges();
            }
            foreach (DataRow dr1 in dtcreateGroupForum.Rows)
            {
                dr1["GroupName"] = "joined the Group";
                dr1.AcceptChanges();
            }
            dsjoin1.Tables.Add(dtjoingroup);
            dsjoin2.Tables.Add(dtcreateGroupForum);
            dsjoin1.Merge(dsjoin2);
           
            DataTable dtrecentActivity = dsjoin1.Tables[0];
            dtrecentActivity.DefaultView.Sort = "date desc";
            dtrecentActivity.AcceptChanges();
            DataView dv = new DataView(dtrecentActivity);
            dv.Sort = "date desc";
            dtRecentActivity = dv.ToTable("dtrecentActivity");
            //dtRecentActivity = dtrecentActivity;
            dtRecentActivity.AcceptChanges();
            //GridView1.DataSource = dtRecentActivity;
            //GridView1.DataBind();
            //DataView dv = new DataView(dtrecentActivity);
            //dv.Sort = "date desc";
            //DataTable dtrecentActivityNew = dv.Table;
       
        }

No comments :

Post a Comment

Contact Us

Name

Email *

Message *