Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


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 many types of validation controls are provided by ASP.NET?

8 Answers  


what is state management in ASP.NET

2 Answers   MCN Solutions,


What is round trip in asp.net?

0 Answers  


Explain the differences between Server-side and Client-side code?

12 Answers   Cognizant, CTS, Siebel Systems, Visual Soft,


HI, I have a very important query in mind. Please help me regarding this. I don't have any real time exp in .net. But I have a knowledge it .net. I got an offer from an MNC company as a software developer has I had kept 2 years of fake exp. Even though for this job I had worked hard to crack interview for more then a year. So, I would like to know how difficult it will be for working in real time as I don't have real time exp. Please tell me as soon as possible bcoz I need to join by next month. Can i sustain over there for a longer time or not. And also let me know how to work pressure will be over there. Please help me regarding this. I'm getting tension thinking about it. Thank you.

1 Answers   CTS,






When would you not use the oleDbConnection object? a) To connect to an SQL 7.0 database. b) To connect to a DB/2 database. c) To connect to an Access database. d) To connect to an SQL 6.5 database.

6 Answers   Syntax Softtech,


What is server infrastructure?

0 Answers  


How do I open an ashx file in windows 7?

0 Answers  


Can we use the java script code in .Net Code behind?

5 Answers   eXensys,


What is mvc in angular?

0 Answers  


What is the function of new view engine in asp.net? : asp.net mvc

0 Answers  


when will garbage collector run?

1 Answers  






Categories