Link to home
Start Free TrialLog in
Avatar of AlexPonnath
AlexPonnathFlag for United States of America

asked on

VB.Net Datareader How to access more than one table

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 ?
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
        connection.Open()
        Dim reader As SqlDataReader = selectCommand.ExecuteReader(CommandBehavior.CloseConnection)
       
        Do While reader.Read
       ' DO something here
        Loop
        reader.Close()
        connection.Close()


HTH
Regards :)
>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 :-)
Ok, could you demonstrate how to use the dataReader.NextResult() against SP ?
Thanks :)
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;"


by:
strSql = "Exec procedurename"

and you have it.
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 :)