首页 > 解决方案 > vb.net linq 查询多个信息

问题描述

我有一个数据表 treno1,其中包含 10 个关于团体铁路预订的列。我需要知道一些信息:从每辆旅行车的城市所有目的地我从网上获得 json 预订。

With treno1
    .Columns.Add("Departure", System.Type.GetType("System.String"))
    .Columns.Add("Arrival", System.Type.GetType("System.String"))
    .Columns.Add("PNR", System.Type.GetType("System.String"))
    .Columns.Add("Level", System.Type.GetType("System.String"))
    .Columns.Add("Last Name", System.Type.GetType("System.String"))
    .Columns.Add("Car", System.Type.GetType("System.String"))
    .Columns.Add("seat", System.Type.GetType("System.String"))
    .Columns.Add("first name", System.Type.GetType("System.String"))
    .Columns.Add("Train", System.Type.GetType("System.String"))
    .Columns.Add("ID res", System.Type.GetType("System.String"))
End With


    For Each item As JProperty In data
        item.CreateReader()
    
        For Each msg As JObject In item.Values
            treno1.Rows.Add(msg("departureLocationName"), msg("arrivalLocationName"), msg("pnrCode"), msg("serviceLevel"), msg("lastName"), msg("wagon"), msg("seat"), msg("firstName"), msg("transportMeanName"), msg("Id"))
        Next
    Next`

在这里我得到了一些信息

Dim destinations = From n In table1.AsEnumerable()
                           Where n.Field(Of String)("Departure") = ComboBox1.SelectedValue
                           Select n.Field(Of String)("Arrival")


Dim wagons = From n In table1.AsEnumerable()
                       Where n.Field(Of String)("Departure") = ComboBox1.SelectedValue
                       Select n.Field(Of String)("wagon")


Dim wagonlist = (wagons.Distinct).ToList
Dim destinations = (destination.Distinct).ToList
     

现在得到:货车号码目的地和该目的地的人怎么可能是查询?例如:从罗马(combobox1.selectevalue)货车 1 - 10 人登机 - 5 佛罗伦萨,3 博洛尼亚 - 2 米兰货车 2 - 14 人登机 - 5 佛罗伦萨,3 博洛尼亚 - 2 米兰,4 皮亚琴察等...怎么可能查询

我做了这个,但它没有做出正确的输出。

    For Each value In wagonlist
        Dim destinazioneglobale = From n In treno1.AsEnumerable()
                                          Where n.Field(Of String)("Departure") = ComboBox1.SelectedValue And n.Field(Of String)("Wagon") = value
                                          Select n.Field(Of String)("Arrival")
    
For Each element In destinazioneglobale
    Dim count4 = treno1.AsEnumerable().Count(Function(row) (row.Field(Of String)("Departure") = ComboBox1.SelectedValue) And (row.Field(Of String)("Arrival") = element))
    ListBox11.Items.Add(value.ToString & (element.ToString))
    Next
            Next

标签: vb.netlinq

解决方案


推荐阅读