在一个数组列表比较值在vb.net数据集数据 [英] compare data in a vb.net dataset with values in an array list

查看:461
本文介绍了在一个数组列表比较值在vb.net数据集数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找通过数据搜索,查看是否有项目存在的一种有效方式。我有〜6000项的数组列表,我需要确定由在所述数据集的特定列用数据数组列表内比较每个项目其中那些并不在数据集中存在

我试图遍历每个项目在ArrayList中的数据集的每个而是没完没了。然后,我尝试使用下面的方法的RowFilter。其中零看起来是有效的。任何帮助是极大的AP preciated,因为你可以告诉我没有太大的程序员...

例如:

 昏暗alLDAPUsers作为ArrayList的
alLDAPUsers = clsLDAP.selectAllStudents昏暗curStu,maxStu作为整数
maxStu = ​​alLDAPUsers.Count对于curStu = ​​0〜maxStu - 1
     昏暗DomainUsername作为字符串=
     DomainUsername = alLDAPUsers.Item(curStu)的ToString     昏暗filteredView由于数据视图
     filteredView = dsAllStudents.Tables(0).DefaultView
     filteredView.RowFilter =
     filteredView.RowFilter =szvausr_un ='与& DomainUsername&安培; '     昏暗returnedrows作为整数= filteredView.Count
     如果returnedrows = 0。然后
          ''删除用户...
     万一
下一个


解决方案

您可以通过排序列表和订购数据集获得更好的性能。然后你就可以走在一起,匹配,当您去。因为你可能已经订购在创建它的SQL查询至少(或者,你应该)数据集,使得这一步骤基本上是免费的,这一点尤其如此。

您应该考虑使用通用的清单,而不是一个ArrayList,并在现有的code其他一些文体几点:

 昏暗LDAPUsers方式列表(串)= clsLDAP.selectAllStudents对于每个DomainUsername作为字符串在LDAPUsers
     昏暗filteredView由于数据视图= dsAllStudents.Tables(0).DefaultView
     filteredView.RowFilter =szvausr_un ='与& DomainUsername&安培; '     如果filteredView.Count = 0则
      ''删除用户...
     万一
下一个

这做同样的事情,你原来的片段,但在一半的空间,因此它是更清洁,更具有可读性。

I'm looking for an efficient way of searching through a dataset to see if an item exists. I have an arraylist of ~6000 items and I need to determine which of those doesn't exist in the dataset by comparing each item within the arraylist with data in a particular column of the dataset.

I attempted to loop through each item in the dataset for each in the arraylist but that took forever. I then attempted to use the RowFilter method below. None of which looks to be efficient. Any help is greatly appreciated, as you can tell I'm not much of a 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

解决方案

You can get better performance by Sorting the list and ordering the dataset. Then you can walk them together, matching as you go. This is especially true since you are probably already ordering the dataset at least (or, you should be) in the sql query that creates it, making that step essentially free.

You should consider using a generic list rather than an ArrayList, and some other stylistic points on your existing code:

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

This does the same thing as your original snippet, but in half the space so it's much cleaner and more readable.

这篇关于在一个数组列表比较值在vb.net数据集数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆