moving backward to write in TableAdapter / DataTable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a problem by writing content in my DataTable. All is working
fine, but when I refer to the last row (or better: all rows before the
activeRow), I can't manipulate the fields. Nothing happens...

My code goes something like this:

Dim dtFragebogen As dbFragebogen.dtFragebogenDataTable
Dim taFragebogen As New
dbFragebogenTableAdapters.dtFragebogenTableAdapter
Dim rowTemp As dbFragebogen.dtFragebogenRow

'here I get the data
taFragebogen.dtFragebogen = .getFBbyFktNrFB(1, activeAnzeige, 1)

With dtFragebogen

activeRow = -1

For Each rowTemp In dtFragebogen

activeRow = activeRow + 1

If activeRow > 5 Then

'*** this works fine ***
.Rows(activeRow).Item("Steuerung") = 888

'*** this doesn't work ***
.Rows(activeRow - 1).Item("Steuerung") = 999

End If

next rowTemp

end With

Where is the problem and how can I fix it???

Thanks, Kersten
 
When it processes the first row, it sets activeRow to 0,
and then tries to set the item on row(-1), which doesn't
exist.

Robin S.
 
that's not the problem (there is a):

--> activeRow > 5

I mean a general problem when writing in rows behind the active (not
reading, that works)
 
Is ActiveRow defined as an integer?

What if you do this instead:


activeRow = -1
For rowNum as Integer = 0 to dtFragebogen.Rows.Count - 1
Dim rowTemp as DataRow = CType(dtFragebogen.Rows(rowNum), DataRow)
rowTemp.Items("Steuerung") = 888
If activeRow > 5 Then
Dim rowBefore as DataRow = CType(dtFrageboen.Rows(rowNum - 1),
DataRow)
rowBefore.Items("Steuerung") = 999
...
End If
Next rowNum

I don't know if it will work, because you just changed the value
of that item in the previous iteration of the loop, and that may be
what is causing the problem, although I think it should work.

Robin S.
--------------------------------
 
Cool. You must not be able to access different rows when iterating
through the dataset using "for each row in dataset..." .

Glad it helped.

Robin S.
 
Back
Top