Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
How to concadenate two tables into single table ?

Table 1

Name    city

Raja    Newyork

Guna    claifornia

 

Table 2

DoorNo

25

36


Table 3  (expected Result)

Name    city         DoorNo

Raja    Newyork      25

Guna    claifornia   36


What I have tried:

when i use Merge()

Result i'm getting is


Table 3

Name city

Raja Newyork

Guna claifornia


DoorNo

25

36
Posted
Updated 27-Apr-16 2:14am
v2
Comments
ZurdoDev 27-Apr-16 7:55am    
Click Improve question and show the code you are using.

Also, how do the 2 tables relate?
kedar001 27-Apr-16 7:55am    
please check.
http://www.w3schools.com/sql/sql_join.asp
rajah rajah 27-Apr-16 7:57am    
hi kedar ,

thanx for the reply . How about in c# ? i'm looking in c#
kedar001 27-Apr-16 8:00am    
ok ,post your code .
Karthik_Mahalingam 27-Apr-16 8:05am    
You mean List or DataTable ?

1 solution

Check this

C#
DataTable dt1 = new DataTable();
           dt1.Columns.Add("Name");
           dt1.Columns.Add("city");
           dt1.Rows.Add("Raja", "Newyork");
           dt1.Rows.Add("Guna", "claifornia");


           DataTable dt2 = new DataTable();
           dt2.Columns.Add("DoorNo");
           dt2.Rows.Add(25);
           dt2.Rows.Add(36);


           DataTable dt3 = new DataTable();
           dt3.Columns.Add("Name");
           dt3.Columns.Add("city");
           dt3.Columns.Add("DoorNo");

           if (dt1.Rows.Count == dt2.Rows.Count)
               for (int i = 0; i < dt1.Rows.Count; i++)
                   dt3.Rows.Add(dt1.Rows[i]["Name"], dt1.Rows[i]["city"], dt2.Rows[i]["DoorNo"]);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900