Re: Finding row by a non-primary key



Hi Val. After reading your answer I still have some questions:

I defined the secondary key using the schema editor command 'Add, New key':

1. Will the datatable generate an index for this key?
2. Will the select command use this index to locate the row?

(I don't want to do anything that will result in a full table scan since
this is an operation I need to perform very frequently. If the Select command
result in an entire table scan, I believe a DataView would be a better
solution. SQL select is not an option in my case.)

Thanks again,
Kjetil


"Val Mazur (MVP)" wrote:

> 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
    ... 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)
  • Re: Finding row by a non-primary key
    ... DataView could be "too much" for this task. ... > primary key. ... > guess this is wasteful since it probably requires generating a new index ... > the secondary key instead of using the index already existing in the ...
    (microsoft.public.data.ado)