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

Answers were Sorted based on User's Feedback



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

Answer / senthil kumar

you can use the query to merge the fields.that query will
be executed through the sqlcommand.

Is This Answer Correct ?    22 Yes 8 No

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

Answer / 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

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

Answer / sunil kumar

DataTable dt1 = retDT("select col1,col2 from Table1");
DataTable dt2 = retDT("select col3,col4 from Table2");
dt1.Merge(dt2);

retDT is a funtion to return datatable based on the query.

The output will be like below
if you check the dt1 content then the output will be

col1 col2 col3 col4
1 2 3 4

Is This Answer Correct ?    21 Yes 15 No

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

Answer / prakash

You Can Write Query :

select (databasename).(owner).(tablename1).
(datafield),select (databasename).(owner).(tablename2).
(datafield) from (databasename).(owner).(tablename1),
(databasename).(owner).(tablename2)


Example:select
LSKGROUP.dbo.addsites.state,LSKGROUP.dbo.employee.empname
from LSKGROUP.dbo.addsites,LSKGROUP.dbo.employee

and then fill the values to new dataset table.

Remember:

if database also differ put databse's name accordingly




Good Luck.....

Is This Answer Correct ?    13 Yes 8 No

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

Answer / abc

DataTable dt1 = retDT("select col1,col2 from Table1");
DataTable dt2 = retDT("select col3,col4 from Table2");
dt1.Merge(dt2);

retDT is a funtion to return datatable based on the query.

The output will be like below
if you check the dt1 content then the output will be

Is This Answer Correct ?    3 Yes 0 No

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

Answer / k

get data from first table and add it as a column in another
table and do the same way to retrive the second data from
other table.Add it to third column..

Is This Answer Correct ?    9 Yes 11 No

Post New Answer

More ASP.NET Interview Questions

How we handle the runtime database schema change issue in asp.net application?

2 Answers   IBM, Tech Mahindra,


What is the need to give <compilation debug=true> command ?

3 Answers   Netsweeper,


How you can use video conferencing in asp.net? guys plz help me ...

2 Answers  


Whats MSIL, and why should my developers need an appreciation of it if at all?

3 Answers   Siebel,


Which library is used by the testers and developers to develop automated tests and create testing tools?

0 Answers  






How do you manage session in ASP and ASP.NET?

1 Answers   Microsoft,


Can you explain the difference between an ADO.NET Dataset and an ADO Recordset?

3 Answers   HCL, Wipro,


How do I open an ashx file in windows 7?

0 Answers  


Explain the namespace classes used in asp.net mvc? : asp.net mvc

0 Answers  


What is http response header?

0 Answers  


Why session is more secure than cookies?

0 Answers  


Where the viewstate is stored after the page postback?

0 Answers  


Categories