Urgent! trying to get a recursive datareader to work

Posted on 2006-03-22
Last Modified: 2008-02-01
this grabs a number and a product, if the number and product exists, it processes it in get_row(), then it checks for a last job number, if it exists, calls itself again, otherwise it exists. Dont know what i'm doing wrong. I'm closing it, and I get the error message

Invalid attempt to Read when reader is closed.
happens on the line --->While r.Read()

    Public Shared Sub recursive(ByVal strVT_Number As String, ByVal strVT_Product As String)
        Dim strVT_Last As String
        Dim strVT_Prod As String
        Dim sqlCommtest As New SqlCommand("SELECT vt_job_number, vt_product, vt_last_job_number FROM vt_newsletters WHERE (vt_print_outside = 1) AND vt_product = '" & strVT_Product & "' and vt_job_number = " & strVT_Number, conRow)
        Dim r As SqlDataReader = sqlCommtest.ExecuteReader()
        While r.Read()
            Get_Row(r("vt_job_number"), r("vt_product"))
            If r("vt_last_job_number") <> "" Then
                strVT_Last = r("vt_last_job_number")
                strVT_Prod = r("vt_product")
                recursive(strVT_Last, strVT_Prod)
            End If
        End While
        DR = DSGrid.Tables(0).NewRow
    End Sub
Question by:Term56
    LVL 9

    Expert Comment

    Do this:

    Dim r As SqlDataReader = sqlCommtest.ExecuteReader(CommandBehavior.CloseConnection)
    That should work
    LVL 9

    Expert Comment

    It might be Data.CommandBehavior.CloseConnection..Sometimes its this way..

    LVL 9

    Accepted Solution

    Also you closed the reader in the while loop. Thats not correct.

    Reader should be closed only aftet the while loop.

    if you want to exit the loop after else use exit while or something like that

    Author Comment

    none of the answers has helped, please cancel the open ticket

    thank you.

    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

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    737 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

    18 Experts available now in Live!

    Get 1:1 Help Now