Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Iterating through records of a DataView with a filter
Message
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
00726538
Message ID:
00726583
Views:
18
Cathi,

You are a lifesaver. I never even really saw this kind of access in the few examples I found. Thanks a lot.

I should have realized it when I changed dv.Tables.Rows.Count to dv.Count I need to do that with all data access.

Doug
>Hi Doug,
>
>What's happening in your code is you are accessing the rows in the DataTable and not the rows in the DataView in your for loop.
>
>Try this:
>
>
>for(int myControl = 0; myControl < dv.Count; myControl++)
>{
>   controlvalue = dv[myControl]["DataINeed"].ToString();
>
>
>
>>All,
>>
>>I have a DataSet which has data that needs conditional processing.
>>
>>I have the data in a ViewState
>>
>>DataSet ds = (DataSet)ViewState["Components"];
>>DataView dv = new DataView(ds.Tables[0]);
>>
>>
>>The DataSet has 18 records. I then establish a filter
>>
>>dv.RowFilter = "type <> 'RepeatControl'";
>>
>>
>>And dv.Count is correctly set to 16.
>>
>>However, if I am processing through my DataView:
>>
>>for(int myControl = 0; myControl < dv.Count; myControl++)
>>{
>>   controlvalue = dv.Table.Rows[myControl]["DataINeed"].ToString();
>>
>>
>>But what happens is that I can still access rows of the View which do not meet my filter condition (which happen to be rows 0 and 1 in this case). What do I need to do to make this work correctly? dv.Count is set to 16, but I can still look at dv.Table.Row[16] and dv.Table.Row[17].
>>
>>I do notice that if I set my filter to
>>
>>dv.RowFilter = "type = 'RepeatControl'";
>>
>>dv.Count is set to 2 and I cannot access any data above dv.Table.Row[1]?
>>
>>Confused,
>>Doug
Douglas Osborne
Don't spend your life just wishing - http://www.AllGiftRegistry.com
Previous
Reply
Map
View

Click here to load this message in the networking platform