将两个数组列表绑定到Datatable [英] Binding the two array list to a Datatable

查看:194
本文介绍了将两个数组列表绑定到Datatable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有2个arraylist。 Arraylist Name和Arraylist URL ..我需要将它添加到Datatable。

Arraylist名称已添加到数据表的名称列中。但我不知道如何将arralist URL添加到列URL的相同数据表中



这是wat我试过

Hi All,

I have 2 arraylist . Arraylist Name and Arraylist URL..I need to add this to the Datatable.
Arraylist Name is Added to the Datatable for column "Name" ..But i am not sure how to add the arralist URL to the same datatable for column "URL"

Here is wat i tried

dt.Columns.Add("Name")

       For i As Integer = 0 To Name.Count - 1
           Dim dr As DataRow = Nothing
           dr = dt.NewRow()
           dr.Item(0) = Name.Item(i)
           dt.Rows.Add(dr)
       Next





请帮忙。



谢谢。



Please help.

Thanks.

解决方案

让我们看一个例子。如果您有列表a1,a2,a3,您可以使用连接并按用户ID合并数据,例如..

Let's see an example.If you have lists a1,a2,a3 you can use join and merge the data by UserID like..
Dim a1 = New Object() {New With {.userID = 1, .firstName = "first Name", .lastName = "Last Name"}}.ToList()
Dim a2 = New Object() {New With {.userID = 1, .address = "address"}}.ToList()
Dim a3 = New Object() {New With {.userID = 1, .productID = "Product ID", .ProducName = "Product Name"}}.ToList()
Dim results = (From a In a1
    Join b In a2 On a.userID Equals b.userID
    Join c In a3 On a.userID Equals c.userID
    Select New With _
    {
        a.userID,
        a.firstName,
        a.lastName,
        b.address,
        c.productID,
        c.ProducName
    }).ToList()


这篇关于将两个数组列表绑定到Datatable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆