Compare data in vb.net dataset with values ​​in array list

I am looking for an effective way to search through a dataset to find out if an element exists. I have an arraylist of ~ 6000 elements, and I need to determine which one does not exist in the data set by comparing each element in the array with the data in a specific column of the data set.

I tried to skip every item in the dataset for each in an arraylist, but that took forever. Then I tried to use the RowFilter method. None of them look effective. Any help is greatly appreciated as you can say that I am not a very programmer ...

Example:

Dim alLDAPUsers As ArrayList
alLDAPUsers = clsLDAP.selectAllStudents

Dim curStu, maxStu As Integer
maxStu = alLDAPUsers.Count

For curStu = 0 To maxStu - 1
     Dim DomainUsername As String = ""
     DomainUsername = alLDAPUsers.Item(curStu).ToString

     Dim filteredView As DataView
     filteredView = dsAllStudents.Tables(0).DefaultView
     filteredView.RowFilter = ""
     filteredView.RowFilter = "szvausr_un = '" & DomainUsername & "'"

     Dim returnedrows As Integer = filteredView.Count
     If returnedrows = 0 Then
          '' Delete the user...
     End If
Next
+3
source share
5 answers

, . , , . , , , (, ) sql, , .

, ArrayList :

Dim LDAPUsers As List(Of String) = clsLDAP.selectAllStudents

For Each DomainUsername As String in LDAPUsers
     Dim filteredView As DataView = dsAllStudents.Tables(0).DefaultView
     filteredView.RowFilter = "szvausr_un = '" & DomainUsername & "'"

     If filteredView.Count = 0 Then
      '' Delete the user...
     End If
Next

, , , .

+4

Generics. , , , .

SO Generics vs Array List

+2

, , :

for each s as string in LDAPUsers.Except(AllStudents)
    ''Delete the user (s)
next

LDAPUsers AllStudents - List (Of String)

Edit:

, :

LDAPUsers.Except(AllStudents, StringComparer.InvariantCultureIgnoreCase)

..

2:

, :

Dim LDAPUsers as new List(Of String)(alLDAPUsers.Cast(Of String))
Dim AllStudents as new List(OfString)()

for each dr as DataRow in dsAllStudents.Tables(0).Rows
    AllStudents.Add(dr("szvausr_un"))
next

- , , , ...

+2

, linq . , , DataView. datatable ...

dsAllStudents.Tables(0).Select("szvausr_un = '" & DomainUserName & "'")

DataRows. , , , , .

+1

Dim . .

Also remove any instructions you don't need (rowfilter = "")

Dim alLDAPUsers As ArrayList
Dim DomainUsername As String
Dim curStu, maxStu As Integer
Dim filteredView As DataView
Dim returnedrows As Integer

alLDAPUsers = clsLDAP.selectAllStudents
maxStu = alLDAPUsers.Count

For curStu = 0 To maxStu - 1
     DomainUsername = alLDAPUsers.Item(curStu).ToString


     filteredView = dsAllStudents.Tables(0).DefaultView
     filteredView.RowFilter = "szvausr_un = '" & DomainUsername & "'"

     returnedrows  = filteredView.Count
     If returnedrows = 0 Then
          '' Delete the user...
     End If
Next
0
source

Source: https://habr.com/ru/post/1698798/


All Articles