?
Solved

VB.Net Datareader How to access more than one table

Posted on 2007-09-29
6
Medium Priority
?
1,411 Views
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 ?
0
Comment
Question by:AlexPonnath
  • 3
  • 3
6 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 19983492
the datareader has a function, called NextResult. see this tutorial
http://www.dotnetjohn.com/articles.aspx?articleid=23
0
 
LVL 1

Expert Comment

by:kulrom
ID: 19985189
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 :)
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 19985217
>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 :-)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:kulrom
ID: 19985280
Ok, could you demonstrate how to use the dataReader.NextResult() against SP ?
Thanks :)
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 19985296
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.
0
 
LVL 1

Expert Comment

by:kulrom
ID: 19985307
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 :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Loops Section Overview
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

809 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