Baffled by dataset error.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ltfcphil
    New Member
    • Nov 2006
    • 8

    Baffled by dataset error.

    Hi,
    Can anyone offer an explanation please? (Code below).

    I have a program that reads through a dataset looking at items 7 and 8.
    If item 7 has a particular value ("R") then I wish to delete the record.
    A filter 'srsshow' is turned on to activate the feature.

    When the filter is activated, this always returns an error - 'There is no row at position 9'.
    However if the line with the remove statement is disabled, the loop runs right through the file without a problem, indicating that this is the line that is causing trouble. Also, the last 'debug.writelin e ' before the error message returns "line 8".

    What is the problem?
    Why does the 'debug.writelin e' not show "9" as it is executed before the line causing the error?

    Many thanks.
    Phil

    For x = 0 To mdrows - 1

    For y = 7 To 8
    dataread = dt.Rows(x).Item (y)

    'discard records not required

    If y = 7 And srshow = 0 And dataread = "R" Then skiprec = 1
    Next y

    Debug.WriteLine ("line " & x )
    If skiprec = 1 Then dt.Rows.Remove( dt.Rows(x))
    skiprec = 0
    y = 7
    Next x
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    I haven't looked into this in detail yet, but doesn't it seem reasonable that when you remove a row, all subsequent rows move up to fill the gap? In other words, Thus, if there were 9 rows, there are now 8.

    Comment

    • ltfcphil
      New Member
      • Nov 2006
      • 8

      #3
      Originally posted by Killer42
      I haven't looked into this in detail yet, but doesn't it seem reasonable that when you remove a row, all subsequent rows move up to fill the gap? In other words, Thus, if there were 9 rows, there are now 8.


      Thanks for the reply,

      I see your point, but this file has around 100 lines at the moment.
      phil

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by ltfcphil
        I see your point, but this file has around 100 lines at the moment.
        Hm... so much for that idea, then.

        Question: What version of VB is this? I'm only really familiar with the syntax of VB6 (and earlier), but the writeline makes me think .Net - correct?

        Comment

        • ltfcphil
          New Member
          • Nov 2006
          • 8

          #5
          Originally posted by Killer42
          Hm... so much for that idea, then.

          Question: What version of VB is this? I'm only really familiar with the syntax of VB6 (and earlier), but the writeline makes me think .Net - correct?
          Hi,
          You are correct !
          VB 2005 Express :Vis Studio v8, VB .Net v2.
          Phil

          Comment

          Working...