Re: Algorithm for faster search in DataTable
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 06/04/04
- Next message: Andrei Matei: "Re: driver"
- Previous message: anonymous_at_discussions.microsoft.com: "VB and C# app"
- In reply to: Rathtap: "Algorithm for faster search in DataTable"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Andrei Matei: "Re: driver"
- Previous message: anonymous_at_discussions.microsoft.com: "VB and C# app"
- In reply to: Rathtap: "Algorithm for faster search in DataTable"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|