使用Linq从DataTableA中选择行,其中id不在DataTableB中

时间:2017-04-17 10:22:06

标签: vb.net linq

我有两个dataTables,我想从DataTable1中选择所有行,其中id不在DataTable2中。我正在尝试的内容:

Sql = "select *,N°Reçu as NumRecu from V_Sit_J_Vente,V_Bien where  V_Sit_J_Vente.Code_bien=V_Bien.Code_bien and date_situation <= '" + dt2 + "' and date_situation >= '" + dt1 + "'"
  Dim GlobalDataVente As DataTable = utilitaire.getDataSet(Sql).Tables(0)
  Sql = "select * from V_Reserv_Annule"
  Dim GlobalDataAnnule As DataTable = utilitaire.getDataSet(Sql).Tables(0)

 Dim query = (From order In GlobalDataVente.AsEnumerable() _
              Where order!code_projet = tab.Rows(i).Item("code_projet")).ToList

Dim bannedCCList = From c In GlobalDataAnnule.AsEnumerable() _
                                   Where c!type.Equals("Transfert acompte") = False And c!date_annule <= dt2

Dim exceptBanned = From c In query Group Join b In bannedCCList On c.Field(Of String)("N°Reçu") Equals b.Field(Of String)("num_reserv_remplace")
                                  Into j() From x In j.DefaultIfEmpty() Where x Is Nothing Select c

我希望"exceptBanned "包含"query""bannedCCList "以外的所有行use LWP::Simple; my $url = 'http://www.nasdaq.com/dividend-stocks/dividend-calendar.aspx?date=2017-Apr-19'; my $content = get $url; 提前致谢

1 个答案:

答案 0 :(得分:1)

您可以使用Contains

Dim query = (From order In GlobalDataVente.AsEnumerable() _
             Where order!code_projet = tab.Rows(i).Item("code_projet")).ToList

Dim bannedCCList = From c In GlobalDataAnnule.AsEnumerable() _
                   Where c.type.Equals("Transfert acompte") = False And c.date_annule <= dt2
                   Select c.Field(Of String)("num_reserv_remplace")

Dim exceptBanned = From c In query
                   Where Not bannedCCList.Contains(c.Field(Of String)("N°Reçu"))
                   Select c

bannedCCList定义一个生成您要排除的Id值的查询; exceptBannedquery与此ID列表合并到一个只运行一次以返回最终结果的查询中。它的工作方式是这样的,因为bannedCCListIEnumerable。只有在实际使用时才会执行它。