Fastest way to search a dataset.

  • Thread starter Thread starter UJ
  • Start date Start date
U

UJ

I have a dataset that will have say 10000 records in it with the names of
files that are used by the system. I then have a large directory of files
that correspond to that list of files and want to find any files that are in
the directory but not referenced anymore (trying to do cleanup.) I know how
to do all of the stuff but am looking for opinions/suggestions on the
searching of the table. If you have say 10000 records, what's the fastest
way to find a record with a certain value. Here's a code snippet of what I'm
talking about.

GetListOfFilesInUseByDB

GetListOfFilesOnServer

for each File in GetListOfFilesOnServer
if File not in ListOfFilesInUseByDB
deleteFileFromServer
end if
next

I guess what I'm trying to find out the most efficient way to do that 'not
in ListOfFilesInUseByDB'. I know I could filter the datatable. I could also
do a Select on the datatable but since this could have a large number of
records, I wonder if there's a way to put an index on the datatable so it
will search faster....

Any thoughts would be appreciated.

J.
 
UJ,

When you do this kind of operations it depends how many times do you have to
do it with the same datatable (you cannot search datarows in a dataset).

When you want to search more than is in my opinion probably the best
solution the rowcollection.find
http://msdn.microsoft.com/library/d...systemdatadatarowcollectionclassfindtopic.asp

With on the second place the
Dataview.find
http://msdn.microsoft.com/library/d...tml/frlrfsystemdatadataviewclassfindtopic.asp

The first returns a row the second an index inside the dataview.

I hope this helps,

Cor
 
10.000 is not so much

i would solve this with a Hashtable wich is as far as i know the one with
the highest search performance ( have seen some Balena test code and believe
me it is fast )
it looks to be ideal in your situation as it exposes a ContainsKey method
wich would hold in your situation the file name

if you do not have a value to store just put in a empty string var

happy coding

M. posseth
 
Back
Top