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 VB2005 express program that reads through a dataset (approx 100 records) 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 the 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

    Code:
    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
    Last edited by willakawill; Feb 25 '07, 06:12 PM. Reason: please use code tags when posting code
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Hi. Looks like you have a problem with the number of rows that are left after you remove one. You may have to recount or reset after you delete a row in order to continue with the loop

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Ok, I'm not familiar with the dataset manipulation code you're using, so don't take me too seriously - I'm just curious. In this code...
      Code:
      dt.Rows.Remove([U]dt.Rows(x)[/U])
      I would have expected to see a simple row number as the parameter, rather than an actual row object. In other words, how come it isn't simply...
      Code:
      dt.Rows.Remove([U]x[/U])
      Or have I just got the syntax wrong?

      Comment

      • ltfcphil
        New Member
        • Nov 2006
        • 8

        #4
        Originally posted by Killer42
        Ok, I'm not familiar with the dataset manipulation code you're using, so don't take me too seriously - I'm just curious. In this code...
        Code:
        dt.Rows.Remove([U]dt.Rows(x)[/U])
        I would have expected to see a simple row number as the parameter, rather than an actual row object. In other words, how come it isn't simply...
        Code:
        dt.Rows.Remove([U]x[/U])
        Or have I just got the syntax wrong?


        Hi,
        Thanks for the reply.
        I have tried your suggestion, but if I simply put a number in the brackets, I get a syntax error.

        Phil

        Comment

        • willakawill
          Top Contributor
          • Oct 2006
          • 1646

          #5
          Originally posted by ltfcphil
          Hi,
          Thanks for the reply.
          I have tried your suggestion, but if I simply put a number in the brackets, I get a syntax error.

          Phil
          And, good heavens, did you completely ignore what I said? Is my handle not cool enough? My picture too girly for you?

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by willakawill
            And, good heavens, did you completely ignore what I said? Is my handle not cool enough? My picture too girly for you?
            Who can take a mere face seriously, compared to an impressively animated orange swirl? :p

            Seriously itfcphil, you should pay attention to willakawill, who is much more familiar with this area. I was just guessing, based on what the syntax looked like.

            Comment

            Working...