Re: Algorithm for faster search in DataTable

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 06/04/04


Date: Fri, 4 Jun 2004 20:01:31 +0100

Rathtap <amcniw@yahoo.com> wrote:
> I read claims from a file into a DataTable and DataRow and then use
> the data adapter's Update method to push those claims into the
> database.
> I import a few thousand claims at a time and before adding a claim to
> the DataTable I need to check if a claim with the same pk has already
> been added to the DataTable. If not I run a stored Proc to do the same
> check in the database. Pseudocode looks loke this:
> -----------------------------------------------
> for(int i = 0;i< tblClaims.Rows.Count;i++)
> {
> //look for claim_id and others(PK is 6 fields)
>
> //if found return
> }
> //If not found look in the database
> -----------------------------------------------
> As you can imagine, more claims added to the table means that many
> more loops. This is slowing my code down. What is a good algorithm I
> can use so that I cut down the number of loops?

If you use a DataView with a RowFilter which looks for things, I
believe it will do a fair amount of work to make things quicker if
you've specified the primary key in the schema.

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages

  • Algorithm for faster search in DataTable
    ... the data adapter's Update method to push those claims into the ... check in the database. ... can use so that I cut down the number of loops? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How do I set-up secure automated file push and pull?
    ... How do I set-up secure automated file push and pull? ... 2* with rsync ... I setup a little shellscript which runs SSH: ... I transfer some backups of our databases from the database account to ...
    (Focus-SUN)
  • ADO.net update problem with VB and MS Access
    ... ADO.net to retrieve the information from the database. ... the update method in ADO.NET should be able to ... Private Sub SaveData() ... Protected Sub initalizeDataAdapter(ByVal cmdSel As OleDbCommand, ...
    (microsoft.public.dotnet.framework.adonet)
  • ADO update problem
    ... ADO.net to retrieve the information from the database. ... the update method in ADO.NET should be able to ... Private Sub SaveData() ... Protected Sub initalizeDataAdapter(ByVal cmdSel As OleDbCommand, ...
    (microsoft.public.vb.database.ado)
  • Re: DataSet updates
    ... > individual DataTables. ... > DataSet back to the database. ... and how the DataSet processes multiple records on the database ... > when it's Update method is called. ...
    (microsoft.public.dotnet.framework.aspnet)