[英]How do i use “select” for a datatable with “not in (a subquery)”
我想在數據表dt1
上執行此查詢:
select * from dt1 where col1 NOT IN(select col1 from dt2)
這是測試代碼:
Sub Main()
Dim dt1 As New DataTable
Dim dt2 As New DataTable
Dim dt3 As New DataTable
dt1.Columns.Add("col1")
dt1.Columns.Add("col2")
dt1.Columns.Add("col3")
dt1.Rows.Add("1", "a", "a")
dt1.Rows.Add("2", "b", "b")
dt1.Rows.Add("3", "c", "c")
dt1.Rows.Add("4", "d", "d")
dt1.Rows.Add("5", "e", "e")
dt2.Columns.Add("col1")
dt2.Columns.Add("col4")
dt2.Columns.Add("col5")
dt2.Rows.Add("1", "a", "a")
dt2.Rows.Add("2", "f", "f")
dt2.Rows.Add("3", "g", "g")
dt3.Columns.Add("col1")
dt3.Columns.Add("col2")
dt3.Columns.Add("col3")
'Dim rows() As DataRow = dt1.Select("dt1.select(columns(0)) Not In (dt2.select(cloumns(0)))")
End Sub
看看Enumerable.Except方法。 例:
dt2.AsEnumerable.Except(dt1.AsEnumerable, DataRowComparer.Default)
根據您認為的“不在Dt2中”,您可能需要定義自定義IEqualityComparer 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.