问题
I'm using this code to filter my datatable by dataview:
Dim xBlockedAccounts As String = "1,5,7"
Dim xDv_AllAcc As New DataView(MyVar_Dt_Accounts)
xDv_AllAcc.RowFilter = "FIND_IN_SET(AccID," & xBlockedAccounts & ")"
Me.Dgv3.DataSource = xDv_AllAcc.ToTable
but it gives me that:
The expression contains undefined function call FIND_IN_SET().'
how I can use FIND_IN_SET function with Rowfilter of Dataview?
回答1:
I assumed MyVar_Dt_Accounts
was a DataTable
. You need to have an array of blocked accounts values. Then the Linq magic.
Private Sub OPCode()
Dim MyVar_Dt_Accounts As New DataTable
Dim xBlockedAccounts = {"1", "5", "7"}
Dim dt = (From row As DataRow In MyVar_Dt_Accounts.AsEnumerable
Select row
Where xBlockedAccounts.Contains(row("AccID").ToString)).CopyToDataTable
Dgv3.DataSource = dt
End Sub
Check first that AccID
is really a string in the database and not a number.
来源:https://stackoverflow.com/questions/66034760/how-to-use-find-in-set-with-dataview-rowfilter-in-vb-net