How to merge 2 tables fields in DataTable in asp.net

Answer Posted / ankur sehgal

Consider a dataset(ds) having two datatables or we can say
that it contains data from two tables..

System.Data.DataTable dt = new DataTable();
dt.Columns.Add("Field1", typeof(string));
dt.Columns.Add("Field2", typeof(string));

if(ds.Tables[0].Rows.Count > 0)
{
foreach(DataRow dr in ds.Tables[0].Rows)
{
DrNew = dt.NewRow();
DrNew[0] = dr["Field1"].ToString();
}
}

if(ds.Tables[1].Rows.Count > 0)
{
foreach(DataRow dr in ds.Tables[1].Rows)
{
DrNew = dt.NewRow();
DrNew[0] = dr["Field2"].ToString();
}
}
dt.AcceptChanges();

Is This Answer Correct ?    22 Yes 15 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a web server? What are the load limits in it?

575


Where is the view state data stored?

556


How can u debug your .net application?

570


How you will manage the state of ASP.NET controls?

557


Why is an object pool required?

594






What are the server controls in asp.net?

446


What are the page life cycle events?

481


In which situation can you not use a viewstate?

520


What is a gridview in asp.net?

514


What is asp.net and how it works?

503


What does asp stand for in asp.net?

507


What is the difference between GridView and Repeater controls in ASP.NET?

565


What is the difference between executescalar and executenonquery?

502


What is voluum?

525


Explain About duration in caching technique

606