Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C# Programming

DataTable.Select vs DataTable.rows.Find vs foreach


Hello,
What is the best way (performance wise) to search for a row in a table?
Let say I have a column named "col1" and what to get the row that the value
of "col1" is "It is me"...
I can set this column as the primary key to use the find method if it worths
it.
So my options are:
1- using the DataTable.Select method and provide a criteria like "col1 = 'It
is me'"
2- creating a primary with "col1" and use the DataTable.Rows.Find("It is
me")
3- using a foreach statement to loop thru each row of the table and find the
row where the value of "col1" = "It is me"

any other better ways?

Thanks,
David

Dave,

    If it weren't for the primary key, I would say it would depend on the
selectivity of your filter.  For filters that are not highly selective
(which return a large number of rows), I would say that looping through the
records is probably the fastest (of course, your own tests should confirm
this, as we might have different definitions of "large" and "selective").

    However, you did indicate that you had the option of using a primary
key, which indicates that there is a high selectivity for this query (since
each value would be unique).  In this case, I think that creating the
primary key and then calling Find would be fastest.

--
          - Nicholas Paldino [.NET/C# MVP]
          - m@spam.guard.caspershouse.com

"Dave" <a_smile_is_f@hotmail.com> wrote in message

news:04435854-E3EB-44C0-B96C-434697759242@microsoft.com...

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc