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

Differentiate between structure and class.

750


What is mvc in angular?

735


Is it possible to create web application with both webforms and mvc?

719


what is command line compiler.what are the steps and how it is related to debugging.

1607


What are the disadvantages of asp.net?

783


What is ashx file in asp.net?

735


What is true about application service provider?

658


Where would you use an ihttpmodule, and what are the limitations of any?

755


What is the difference between equals() and == in c#?

746


What is the difference between sealed vs static class?

775


Can the validation occurs in server-side or client-side? If the validation occurs why should we do?

813


Write code to send e-mail from an asp.net application?

757


What does aspcompat="true" mean?

752


What is ispostback method in asp.net?

738


What is the appSettings Section in the web.config file?

783