I am getting the exception "There is no row at position 5" on a dataview
that has 10 rows (count = 10)
The original dataset, i.e. unfiltered, has 12 rows. when it is filtered,
there are 10. i can look in the dataview and see all ten rows. but when i am
in the foreach(DataRowViw pr in orderDV) loop i get the error when i try to
access a field in the sixth row (position 5).
i cannot figure out why i keep getting this exception . does anyone know
why?
thanks
m
I have included the code that causes this error:

string Filter = "BatchID = " + BatchID.ToString(); // usullay BatchID = 0

DS.Tables[OrderTable].DefaultView.RowFilter = Filter;

DataView orderDV = DS.Tables[OrderTable].DefaultView;

foreach(DataRowView pr in orderDV)

{

string Orders_Id = pr["OrderNumber"].ToString(); // why do i get an
exception here?

//pr["OrderNumber"]
{"There is no row at position 5." } System.IndexOutOfRangeException



foreach (DataRow cr in pr.Row.GetChildRows("OrderCollection"))

{

}

pr["BatchID"] = 1; // assign new BatchID

}

RE: There is no row at position x by v-kevy

v-kevy
Thu Oct 27 21:55:00 CDT 2005

Hi MR,

Could you try to check in the DataTable.Rows collection that if this row
has been deleted? If a row is deleted, the cell values have to be accessed
with a DataRowVersion argument to get the original value.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."


Re: There is no row at position x by MR

MR
Fri Oct 28 01:20:58 CDT 2005

i am not deleting any records. i can see the record in the dataset

"Kevin Yu [MSFT]" <v-kevy@online.microsoft.com> wrote in message
news:eShIFs22FHA.2904@TK2MSFTNGXA01.phx.gbl...
> Hi MR,
>
> Could you try to check in the DataTable.Rows collection that if this row
> has been deleted? If a row is deleted, the cell values have to be accessed
> with a DataRowVersion argument to get the original value.
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>



Re: There is no row at position x by MR

MR
Fri Oct 28 02:55:58 CDT 2005

upon closer examination, i see that the DataViews count = 5.
so how does the foreach iterator/index allow more than 5 iterations?



"MR" <comconix@newsgroup.nospam> wrote in message
news:%23a$ZGf42FHA.2600@tk2msftngp13.phx.gbl...
>i am not deleting any records. i can see the record in the dataset
>
> "Kevin Yu [MSFT]" <v-kevy@online.microsoft.com> wrote in message
> news:eShIFs22FHA.2904@TK2MSFTNGXA01.phx.gbl...
>> Hi MR,
>>
>> Could you try to check in the DataTable.Rows collection that if this row
>> has been deleted? If a row is deleted, the cell values have to be
>> accessed
>> with a DataRowVersion argument to get the original value.
>>
>> Kevin Yu
>> =======
>> "This posting is provided "AS IS" with no warranties, and confers no
>> rights."
>>
>
>



Re: There is no row at position x by Bart

Bart
Fri Oct 28 03:11:07 CDT 2005

Hi,

"MR" <comconix@newsgroup.nospam> wrote in message
news:uHHt2002FHA.472@TK2MSFTNGP15.phx.gbl...
>I am getting the exception "There is no row at position 5" on a dataview
>that has 10 rows (count = 10)
> The original dataset, i.e. unfiltered, has 12 rows. when it is filtered,
> there are 10. i can look in the dataview and see all ten rows. but when i
> am in the foreach(DataRowViw pr in orderDV) loop i get the error when i
> try to access a field in the sixth row (position 5).
> i cannot figure out why i keep getting this exception . does anyone know
> why?
> thanks
> m
> I have included the code that causes this error:
>
> string Filter = "BatchID = " + BatchID.ToString(); // usullay BatchID = 0
>
> DS.Tables[OrderTable].DefaultView.RowFilter = Filter;
>
> DataView orderDV = DS.Tables[OrderTable].DefaultView;
>
> foreach(DataRowView pr in orderDV)
>
> {
>
> string Orders_Id = pr["OrderNumber"].ToString(); // why do i get an
> exception here?
>
>
> //pr["OrderNumber"] {"There is no row at position 5." }
> System.IndexOutOfRangeException
>
>
>
> foreach (DataRow cr in pr.Row.GetChildRows("OrderCollection"))
>
> {
>
> }
>
> pr["BatchID"] = 1; // assign new BatchID

Yes, but if there is a filter like "BatchID = 0" then this DataRowView will
dissappear from the DataView because it no longer passes the filter now.

If you are certain that all rows will get excluded because of the filter,
then you could use a loop like :

string Filter = "BatchID = " + BatchID.ToString(); // usullay BatchID = 0
DS.Tables[OrderTable].DefaultView.RowFilter = Filter;
DataView orderDV = DS.Tables[OrderTable].DefaultView;

while ( orderDV.Count > 0 )
{
DataRowView pr = orderDV[0];
string Orders_Id = pr["OrderNumber"].ToString();
....

// this rows gets excluded because of rowfilter and so count decreases
pr["BatchID"] = 1;
pr.EndEdit();
}

HTH,
Greetings

>
> }
>
>



Re: There is no row at position x by MR

MR
Fri Oct 28 03:29:07 CDT 2005

yes of course!
i forgot that the filter is dynamic
thanks
m

"Bart Mermuys" <bmermuys.nospam@hotmail.com> wrote in message
news:uJk9td52FHA.3036@TK2MSFTNGP15.phx.gbl...
> Hi,
>
> "MR" <comconix@newsgroup.nospam> wrote in message
> news:uHHt2002FHA.472@TK2MSFTNGP15.phx.gbl...
>>I am getting the exception "There is no row at position 5" on a dataview
>>that has 10 rows (count = 10)
>> The original dataset, i.e. unfiltered, has 12 rows. when it is filtered,
>> there are 10. i can look in the dataview and see all ten rows. but when i
>> am in the foreach(DataRowViw pr in orderDV) loop i get the error when i
>> try to access a field in the sixth row (position 5).
>> i cannot figure out why i keep getting this exception . does anyone know
>> why?
>> thanks
>> m
>> I have included the code that causes this error:
>>
>> string Filter = "BatchID = " + BatchID.ToString(); // usullay BatchID = 0
>>
>> DS.Tables[OrderTable].DefaultView.RowFilter = Filter;
>>
>> DataView orderDV = DS.Tables[OrderTable].DefaultView;
>>
>> foreach(DataRowView pr in orderDV)
>>
>> {
>>
>> string Orders_Id = pr["OrderNumber"].ToString(); // why do i get an
>> exception here?
>>
>>
>> //pr["OrderNumber"] {"There is no row at position 5." }
>> System.IndexOutOfRangeException
>>
>>
>>
>> foreach (DataRow cr in pr.Row.GetChildRows("OrderCollection"))
>>
>> {
>>
>> }
>>
>> pr["BatchID"] = 1; // assign new BatchID
>
> Yes, but if there is a filter like "BatchID = 0" then this DataRowView
> will dissappear from the DataView because it no longer passes the filter
> now.
>
> If you are certain that all rows will get excluded because of the filter,
> then you could use a loop like :
>
> string Filter = "BatchID = " + BatchID.ToString(); // usullay BatchID = 0
> DS.Tables[OrderTable].DefaultView.RowFilter = Filter;
> DataView orderDV = DS.Tables[OrderTable].DefaultView;
>
> while ( orderDV.Count > 0 )
> {
> DataRowView pr = orderDV[0];
> string Orders_Id = pr["OrderNumber"].ToString();
> ....
>
> // this rows gets excluded because of rowfilter and so count decreases
> pr["BatchID"] = 1;
> pr.EndEdit();
> }
>
> HTH,
> Greetings
>
>>
>> }
>>
>>
>
>