Home > DeveloperSection > Forums > I have two stored procedures summary1 and summary 2 and get the stored procedures data into two different data table dt1 and dt2 in c#
Royce Roy
Royce Roy

Total Post:134

Points:938
Posted on    May-03-2013 1:35 AM

 C# C# 
Ratings:


 1 Reply(s)
 667  View(s)
Rate this:
Hi Expert!

I want to get data in third data table dt3 in particular format like

if dt1 table are as --

name |   m1 |   m2   |   m3   |
abc  |   12 |   4    |   8    |
dcd  |   1  |   5    |   7    | 
dt 2 table data are as -

name |   m1 |   m2   |   m3   |
abc  |   5  |   5    |   5    |
dcd  |   5  |   5    |   5    | 
both data table have same number of columns with same column name .

i want result in dt3 in this format

name |   m1     |   m2   |   m3   |
abc  |   12/5   |   4/5  |   8/5  |
dcd  |   1/5    |   5/5  |   7/5  |
and bind data table dt3 data to a gridview.

Thanks in advance.



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    May-03-2013 9:10 AM

Hi Royec!

You may use Linq for this,

var dt3 = from p in dt1.AsEnumerable()
                   join q in dt2.AsEnumerable() on p.Field<string>("name") equals q.Field<string>("name") into UP
                   from q in UP.DefaultIfEmpty()
                   select new
                   {
                        name = p.Field<string>("name"),
                        m1 = p.Field<string>("m1") + "/" + q.Field<string>("m1"),
                        m2 = p.Field<string>("m2") + "/" + q.Field<string>("m2"),
                        m3 = p.Field<string>("m3") + "/" + q.Field<string>("m3")
                   };

Don't want to miss updates? Please click the below button!

Follow MindStick