Saturday, September 17, 2016

Batch search! Oh, you make my life so easy

You have a database with millions of records and you need to search for one 100 or even 1000's of those records. Fast! You have  a couple of minutes  before the boss calls again. You have 2 choices. Madly, start typing criteria after criteria, which will definitely take a long time to do, with no guarantee it will yield  the specific records you need  or a second option  would be to take the csv(comma delimited string) file your boss just sent you and use it to search your records  at easy.


First we need to upload our file and read it to a Data Table. Now, we can pass our result to the below method where we can attach a unique batch code to the set which will be useful later when performing our search.


 After we insert our records to the database we need to reset the controls and make it available so that our user can add the records from the file to the filter criteria.


Finally, we  use our batch code and add it to our criteria. (Using NHibernate here for example)


 For this example I only had two scan codes in my Test.csv file. Those two records were returned  since they matched my search criteria but you can see where I am going with this...

No comments:

Post a Comment