Finding row by a non-primary key



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

  • 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)
  • 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)
  • Re: How to get the Position Row using the find method
    ... sorted by primary key you might create a DataView over your table (not ... > I need to know if is possible get the row position Index of a specific row ... really need the position of this returned row in the table. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Best Way INSERT/UPDATE
    ... Assuming I knew the primary Key; ... Then, if @@Rowcount was 0, do an Insert ... Prev by Date: ...
    (microsoft.public.sqlserver)