http://lovetoknowgoogleandmstech.blogspot.com/2009/01/linq-where-in-and-not-in.html
現在來個進階版囉!直接看Code比較快
先來個String字串的Where in
Dim Lot() As String = Split("21003144,21003145", ",")
Dim i1 As Integer = 0
Dim query = From p In db.Packing_Item_Entry_History _
Where (Lot).Contains(p.pieh_Lot_No) _
Select p.pieh_Lot_No, p.pieh_pih_Job_No
DataGridView1.DataSource = query
or
Dim query = From p In db.Packing_Item_Entry_History _
Where (Split("21003144,21003145", ",")).Contains(p.pieh_Lot_No) _
Select p.pieh_Lot_No, p.pieh_pih_Job_No
DataGridView1.DataSource = query
再來個數字版的Where in
Use integer
Dim dkey_arr() As String = Split("14472,14473", ",")
Dim iArray(dkey_arr.Length - 1)
For i As Integer = 0 To dkey_arr.Length - 1
iArray(i) = CType(dkey_arr(i), Integer)
Next
Dim query = From p In db.Packing_Item_Entry_History _
Where (iArray).Contains(p.pieh_dKey) _
Select p.pieh_Lot_No, p.pieh_pih_Job_No
DataGridView1.DataSource = query
或者是
...
Use integer
Dim i_List As New List(Of Integer)
For Each s As String In String.Split("14472,14473", ",")
i_List.Add(CType(s, Integer))
Next
Dim query = From p In db.Packing_Item_Entry_History _
Where (i_List).Contains(p.pieh_dKey) _
Select p.pieh_Lot_No, p.pieh_pih_Job_No
DataGridView1.DataSource = query
Read more.