how to use FIND_IN_SET with dataview.rowfilter in vb.net

安稳与你 提交于 2021-02-11 06:05:20

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!