Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, i am merging two data set.
fields are -
table 1- milestone,completiondate, data set=DS1
table 2- receiptdate,receiptamount- DATA SET= DS2

C#
DS1.Merge(DS2);

when i merge these two table from dataset
it shows result in two different rows.
i want merged result.
i want result in single row.

Thanks in ADvance.
Posted
Updated 12-Apr-12 19:42pm
v3

1 solution

Hi,
Take a look at this simple sample. it may help you:

C#
// This is table one. 
    DataTable t1 = new DataTable(); 
    t1.Columns.Add("key1"); 
    t1.Columns.Add("c1"); 
    t1.PrimaryKey = new[]{t1.Columns["key1"]}; 
    t1.Rows.Add(1, "data1"); 
 

    // This is table two. 
    DataTable t2 = new DataTable(); 
    t2.Columns.Add("key1"); 
    t2.Columns.Add("c2"); 
    t2.PrimaryKey = new[] { t2.Columns["key1"] }; 
    t2.Rows.Add(1, "data2"); 
 

    // Combine table one with table two. 
    t1.Merge(t2, false, MissingSchemaAction.Add); 
 

    // Read "c2" field from table one 
    Response.Write(t1.Rows[0]["c2"].ToString()); 



Cheers
 
Share this answer
 
Comments
sahabiswarup 13-Apr-12 2:08am    
good job
Reza Ahmadi 13-Apr-12 7:23am    
Thanks
mayankshrivastava 13-Apr-12 2:43am    
its not working...
Reza Ahmadi 13-Apr-12 3:17am    
I've tested the above code, it works fine

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