VB.Net Datareader How to access more than one table

Posted on 2007-09-29
Last Modified: 2008-07-17
I have a Stored procedure which is called from my VB.Net app which returns more than on resault.
It actual has 3 diffrent resaults it will return with in the query. My question is how do i access the
diffrent tables / resaults within the reader object ?
Question by:AlexPonnath
    LVL 142

    Accepted Solution

    the datareader has a function, called NextResult. see this tutorial
    LVL 1

    Expert Comment

    Actually NextResult method is useful if you have more than one query that certainly doesn't suit in your case.
    Rather you have a Stored Procedure which returns concrete results.
    So you should do nothing specific in order to display data that SP does return.

    For example:

            Dim selectCommand As SqlCommand = New SqlCommand()
            selectCommand.CommandText = "sp_GetSomething"
            selectCommand.CommandType = CommandType.StoredProcedure
            selectCommand.Connection = connection
            Dim reader As SqlDataReader = selectCommand.ExecuteReader(CommandBehavior.CloseConnection)
            Do While reader.Read
           ' DO something here

    Regards :)
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    >Actually NextResult method is useful if you have more than one query that certainly doesn't suit in your case.
    well, I think I cannot agree ... because of:
    <...>  It actual has 3 diffrent resaults it will return with in the query.  <..>
    of course, we would need to know the procedure code to be 100% sure...
    and also some feedback of the author :-)
    LVL 1

    Expert Comment

    Ok, could you demonstrate how to use the dataReader.NextResult() against SP ?
    Thanks :)
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    see the article I linked to. just replace the:
    strSql = _
             "SELECT CategoryName FROM Categories ORDER BY CategoryName;" _
           & "SELECT Top 10 CompanyName FROM Customers ORDER BY CompanyName;" _
           & "SELECT LastName FROM Employees ORDER BY LastName;" _
           & "SELECT Top 10 ProductName FROM Products ORDER BY ProductName;"

    strSql = "Exec procedurename"

    and you have it.
    LVL 1

    Expert Comment

    Althrough i have never tested something like that, if it works then i believe that your suggestion is actually solution for the Alex's problem.

    Cheers :)

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    746 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

    16 Experts available now in Live!

    Get 1:1 Help Now