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

Securitywise What are the Enhancements in 2.0?

0 Answers   Microsoft,


What r the asp.net list controls and diff. Between them?

0 Answers  


How can we identify that the Page is Post Back?

0 Answers  


What is server infrastructure & server components?

0 Answers  


Explain advantages of caching?

0 Answers  


what is uncle aunty file

1 Answers  


What is a PostBack? What is ViewState? How is it encoded? Is it encrypted? Who uses ViewState? Why is it either useful or evil?

3 Answers   TCS,


From the given paragraph of text, write a program to match the strings of format “Any number of numerals followed by an underscore followed by any number of alphabets" ex:123_abc (Note:using regular expressions)

4 Answers   Microsoft,


By default what is the Asp.Net application login context on IIS 5.0? By default the ASP.Net app runs in the context of a local user ASPNet on IIS version 5. On IIS version 6 on windows 2003 it is called Network service

0 Answers  


suppose we have two object;obj1 and obj2 can we assign obj2 to one1; and if yes; then after assigning suppose we delete obj2 then obj1 will retain obj2 value or not.

3 Answers  


What are assemblies and namespaces and explain the difference between them ?

0 Answers  


what are the Custom controls in asp.net?

0 Answers   MCN Solutions,


Categories