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?

Its better get the resluts from DB once into one datatable and bind 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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.