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
running32Asked:
Who is Participating?
 
SanclerConnect With a Mentor Commented:
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
 
bchoorConnect With a Mentor Commented:
Do while ---> Should be

If rowcount > i then
Dim programmatch...


End If
0
 
Bob LearnedConnect With a Mentor Commented:
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
 
running32Author Commented:
Thank you for you help.  I figured it out.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.