Re: DataView or foreach by William
William
Sat Nov 22 13:40:47 CST 2003
Depending on what your ultimate objective is, I'd either use the Find method
like Miha suggests, or use the RowFilter property. I think your
implementation is slower in the first case, but you could improve it by
using Index based lookups instead of nominal ones (ie currrentRowp[0] vs
currentRow["identitycolumn"])
If you don't have a PK, the second method isn't going to work so you'd have
to use the first or use the RowFilter method, so that's also a variable in
the equation, b/c even in this instance where you may have a key, you may
not always have one - so the 'better' method can be relative.
With all that said, I haven't run any performance traces, but I really doubt
the first method would be faster in most instances, but even if it were,
using Find is much cleaner and more readable (if you did this in say 300
instances in your code where you app had a lot of different searches, you'd
save yourself 600 lines of code....
HTH,
Bill
"Ondrej Sevecek" <ondra@sevecek.com.thisisanuntispamsuffix> wrote in message
news:O1JhSPRsDHA.1196@TK2MSFTNGP12.phx.gbl...
> Hello,
> I would like to find DataRow from some table identified by IDENTITY
column
> value:
>
> foreach (DataRow currentRow in DataTable1)
> {
> if (currentRow["identitycolumn"] == 100)
> {
> break;
> }
>
>
> --or--
>
> new DataView(DataTable1, "identitycolumn = 100", null, ...
>
>
>
> What method is more efficient and how can one determine the efficiency
of
> such different methods in other cases?
>
> Ondra.
>
>
>