开发者

Left Join of Two Data Table into one two DataTabale

开发者 https://www.devze.com 2023-03-29 03:56 出处:网络
Here is my Scenario I Have First Datable :TableA **Item****Place** ItemAPlaceA ItemBPlaceB ItemEPla开发者_运维知识库ceE

Here is my Scenario

I Have First Datable :TableA

     **Item**    **Place**  

      ItemA      PlaceA
      ItemB      PlaceB
      ItemE      Pla开发者_运维知识库ceE

I Have Second Datable :TableB


  **Item**            **Status**
-------------------------------
   ItemC             Complete

   ItemD             Complete

   ItemE             Complete

Output New DataTable Will Look Like This

   Item        Place       Status
----------------------------------------------

   ItemA     PlaceA

   ItemB     PlaceB

   ItemC                Complete

   ItemD                Complete

   ItemE     PlaceE     Complete

Please give me the Solution in VB.Net


As a quick example:

    Dim dt As New DataTable()
    dt.Columns.Add("Serial", Type.GetType("System.String"))
    dt.Columns.Add("Item", Type.GetType("System.String"))
    dt.Columns.Add("Place", Type.GetType("System.String"))
    dt.Rows.Add(New String() {"001", "ItemA", "PlaceA"})
    dt.Rows.Add(New String() {"002", "ItemB", "PlaceB"})


    Dim dt1 As New DataTable()
    dt1.Columns.Add("Serial", Type.GetType("System.String"))
    dt1.Columns.Add("Item", Type.GetType("System.String"))
    dt1.Columns.Add("Status", Type.GetType("System.String"))
    dt1.Rows.Add(New String() {"003", "ItemC", "Complete"})
    dt1.Rows.Add(New String() {"003", "ItemD", "Complete"})

    dt.Merge(dt1)

The last line is the most important, which merges the contents of one datatable with the contents of another.

Should do the trick!!

0

精彩评论

暂无评论...
验证码 换一张
取 消