[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

error in dataset

My sub routine keeps giving me an out of memory error when it tries to execute  programmatch = DataSet901.Tables("tblrecordsmanagement").Rows(i).Item("program")  There is one row retruned in the recordset.  Can someone tell me what programming mistake I have made. Thank you


 DataSet901.Clear()
        SqlDataAdapter2.SelectCommand.Parameters("@param9").Value = lngpatientid
        Dim rowCount As Integer = SqlDataAdapter2.Fill(DataSet901)
        Dim i
        i = 0
        MsgBox(rowCount)
        Do While rowCount <> i
            Dim programmatch
            programmatch = DataSet901.Tables("tblrecordsmanagement").Rows(i).Item("program")
            i = i + 1
            If programmatch = "PA" Then
                Label25.BackColor = Color.Red
                CheckBox5.Checked = True
            End If

            If programmatch = "Medical Services" Then
                Label27.BackColor = Color.Red
                CheckBox4.Checked = True
            End If
            If programmatch = "Dental" Then
                Label26.BackColor = Color.Red
                CheckBox3.Checked = True
            End If
            If programmatch = "HP" Then
                Label25.BackColor = Color.Red
                CheckBox5.Checked = True
            End If
            If programmatch = "Connections" Then
                Label28.BackColor = Color.Red
                CheckBox2.Checked = True
            End If
        Loop
0
running32
Asked:
running32
3 Solutions
 
bchoorCommented:
Do while ---> Should be

If rowcount > i then
Dim programmatch...


End If
0
 
Bob LearnedCommented:
That won't work either, since i is being incremented by i = i + 1 (or i += 1).  If that is true, then you need i < rowcount.

Bob
0
 
SanclerCommented:
Isn't

   rowcount > i

the same as

   i < rowcount?

And how, in any event, does this part of this code produce an out of memory exception?  We're told RowCount starts as 1 and i starts as 0.  On the first pass through

       Do While rowCount <> i

the result is True, so the code executes.  Forgetting all the rest (none of which changes rowCount or i) it hits

            i = i + 1

So on the second pass through

       Do While rowCount <> i

rowCount is still 1 and i has become 1.  The result is False.  The code shouldn't execute again.

So, although I agree that

       Do While rowCount <> i

should be replaced by a more definite test, I reckon something else is happening here.  But I can't see what.

Roger
0
 
running32Author Commented:
Thank you for you help.  I figured it out.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now