Re: Finding row by a non-primary key



Hi,

I believe Select is the best way to do it against DataTable. Using of the
DataView could be "too much" for this task. Another way is to use SELECT SQL
statement against the database

--
Val Mazur
Microsoft MVP

http://xport.mvps.org



"Kjetil" <Kjetil@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3CF6C46C-917C-475D-A292-AA0530EEEBA8@xxxxxxxxxxxxxxxx
>I have a DataTable which contains a secondary unique key in addition to the
> primary key. What is the best way to search for a row with a specific
> value
> for the secondary key?
>
> The DataRowCollection.Find method appears to apply only for the primary
> key.
>
> I could create a DataView and use the Find method of the DataView, but I
> guess this is wasteful since it probably requires generating a new index
> for
> the secondary key instead of using the index already existing in the
> table?
>
> I could use the Select method of the data table, but I am not to happy
> about
> this since it requires converting the column name and key value into
> search
> string, which is not required by the two Find methods above. Also, I am
> not
> sure if this will use an index to locate the row?
>
> Any advise on the best approach is very wellcome (I am using VS2003).
>


.



Relevant Pages

  • Re: Finding row by a non-primary key
    ... I defined the secondary key using the schema editor command 'Add, ... > DataView could be "too much" for this task. ... >> primary key. ...
    (microsoft.public.data.ado)
  • Re: Finding row by a non-primary key
    ... But as I know all the index columns have an internal index. ... > I defined the secondary key using the schema editor command 'Add, ... > result in an entire table scan, I believe a DataView would be a better ...
    (microsoft.public.data.ado)
  • Cant databind hierarchical data
    ... top-level is a DataView on a table. ... This works fine BUT NOT IF the primary key of a parent row ... The phone numbers under Bob are a child view on ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Setting the order of rows stored in a DataTable
    ... I thought specifying a primary key would define the order but ... Using a DataView every time to insure the required sorted order ...
    (microsoft.public.dotnet.framework.adonet)
  • Finding row by a non-primary key
    ... I have a DataTable which contains a secondary unique key in addition to the ... The DataRowCollection.Find method appears to apply only for the primary key. ... I could create a DataView and use the Find method of the DataView, ... Prev by Date: ...
    (microsoft.public.data.ado)