On Oct 8, 1:37*pm, Tom Shelton <tom_shel...@comcast.invalid> wrote:
> TC pretended :
>
> > I'm working on an application which must manipulate data in a DataSet.
> > Very often, I must loop through the rows in a DataTable. To do that,
> > I've been writing code that looks like this:
>
> > For Each ElementRow As DataRow In ElementTable.Select("TRUE", "",
> > DataViewRowState.CurrentRows)
> > ...
>
> > That works, but I suspect it isn't the best way. After all, it seems
> > inappropriate that I should have to provide values for
> > FilterExpression and Sort when I don't want a filter and don't care
> > about the sort order. Have I overlooked a better way to loop through
> > the rows in a DataTable?
>
> > -TC
>
> Is there now Rows property on your datatable? *I never use typed
> datasets (and rarely datasets at all - prefering to use domain objects
> instead) - so, I honestly don't know... But, with a regular datatable,
> you can do:
>
> For Each r As DataRow in MyTable.Rows
> * *...
> Next
>
> There is also the Linq-DataSet extensions if you want 
>
> --
> Tom Shelton
Tom,
Yes, there is a Rows property, but it includes deleted rows. Frankly,
I find ADO.NET to be very confusing in this regard. When you delete a
row, you don't actually delete it. It stays in the DataTable, but you
get an error if you try to use it. In order to work with the current
state of the DataTable -- as I assume most people want to do 99.9% of
the time -- you must somehow filter out deleted rows. One way to do
that is to specify the row state (as with DataViewRowState.CurrentRows
in my example), but I can find no way to specify the row state without
also specifying a filter expression ("TRUE" in my example) and a sort
order ("" in my example).
Thanks for the suggestion about Linq. If necessary, I'll look into it.
However, I don't want to adopt a new technology until I confirm that
1) there is a problem with the old technology; and 2) the new
technology is better. Do you use Linq, and can you recommend it?
-TC