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
Differentiate between structure and class.
What is mvc in angular?
Is it possible to create web application with both webforms and mvc?
what is command line compiler.what are the steps and how it is related to debugging.
What are the disadvantages of asp.net?
What is ashx file in asp.net?
What is true about application service provider?
Where would you use an ihttpmodule, and what are the limitations of any?
What is the difference between equals() and == in c#?
What is the difference between sealed vs static class?
Can the validation occurs in server-side or client-side? If the validation occurs why should we do?
Write code to send e-mail from an asp.net application?
What does aspcompat="true" mean?
What is ispostback method in asp.net?
What is the appSettings Section in the web.config file?