error in dataset

Posted on 2006-05-01
Last Modified: 2010-04-23
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

        SqlDataAdapter2.SelectCommand.Parameters("@param9").Value = lngpatientid
        Dim rowCount As Integer = SqlDataAdapter2.Fill(DataSet901)
        Dim i
        i = 0
        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
Question by:running32
    LVL 10

    Assisted Solution

    Do while ---> Should be

    If rowcount > i then
    Dim programmatch...

    End If
    LVL 96

    Assisted Solution

    by:Bob Learned
    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.

    LVL 34

    Accepted Solution


       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.


    Author Comment

    Thank you for you help.  I figured it out.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now