1.11M Members

vb.net Merge Two Datatable

 
0
 

I have two datatables that generate a datagridview like below:

1) datatable name : grpDT 119
2) datatable name : grpTot 211

I want to merge both datatable so that I the datagridview will be like this:

34

what is the best way to do this?
do i need to create new datatable and merge it?

Attachments
 
0
 

Its better get the resluts from DB once into one datatable and bind it.

 
0
 

Yes you are right.

However, I cannot do it straight from DB because the column Total Lost Time and Average are in Char datatype and I have to convert to timespan to do the summation and get the average for each Operator ID.

In this case, I use LINQ to generate both table.

But the problem is, I dont know how to combine both LINQ statement. That's why I have 2 datatable.

 
0
 

I already solved this problem after few testing since last night. Yeay! (^__^)

Anyway, here is the code:

'''''' Start Join 2 Datatable ''''''

            Dim JoinResult = _
            From o In grpDT.AsEnumerable _
            Join a In grpTot.AsEnumerable _
            On a.Field(Of String)("Tantou") Equals o.Field(Of String)("Tantou") _
          Select New With _
          { _
            Key .operatorID = a.Field(Of String)("Tantou"), _
            Key .totalCount = o.Field(Of Int32)("Count"), _
            Key .TotalSum = a.Field(Of TimeSpan)("Duration"), _
            Key .Average = o.Field(Of TimeSpan)("Duration") _
          }


            DataGridView1.DataSource = JoinResult
Question Answered as of 1 Year Ago by Pgmer
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: