0

here dataset has two tables(table,table1).both have some common fields and common data. while I am binding these two tables into gridview, it shows two rows. I want to bind in single row,like:https://forums.asp.net/t/1963338.aspx?how+to+merge+two+different+rows+of+datatable+into+single+row+in+same+datatable.

Anıl Aşık
  • 360
  • 1
  • 15
Pediredla
  • 19
  • 1
  • 7
  • Can you please show your code ? – Abdul May 17 '17 at 08:20
  • DataTable dt1 = new DataTable(); dt1 = ds.Tables[0]; DataTable dt2 = new DataTable(); dt2 = ds.Tables[1]; DataTable dt3 = new DataTable(); dt3 = dt1.Copy(); dt3.Merge(dt2, false); grdVehicleUtilization.DataSource = dt3; grdVehicleUtilization.DataBind(); – Pediredla May 17 '17 at 09:19
  • Copy dt1 to dt2 , Search and remove duplicate records from dt2 and then assign it to DataSource. check this if it helps http://stackoverflow.com/questions/4415519/best-way-to-remove-duplicate-entries-from-a-data-table – Abdul May 17 '17 at 09:55

1 Answers1

0

i just created temp(dt4) table. and added required fields from two tables. and finaly binded temp table to grdview.`

                if (dt2.Rows.Count > 0)
                {
                    for (int i = 0; i < dt2.Rows.Count; i++)
                    {
                        d4.Rows.Add(dt1.Rows[i][0], dt1.Rows[i][1], dt1.Rows[i][2], dt1.Rows[i][3], dt1.Rows[i][4], dt2.Rows[i][3]);

                        grdVehicleUtilization.DataSource = d4;
                        grdVehicleUtilization.DataBind();
                    }

                }`
Pediredla
  • 19
  • 1
  • 7