Start New Discussion within our Software Development Community

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:


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

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.

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
This question has already been answered. Start a new discussion instead.