DataGrid + Stored Procedure Problem

S

Stephen

Hi,
Question regarding displaying data on Datagrid. it works fine
I have 4 SP's the results of which I feel are too much overhead. so I put
all the 4 queries into as single STP and it runs successfully but only the
first one is bound for eg:

Create PROCEDURE dbo.Sample
(
@id int,
}
as
Select * from Sample1 where id = @id
Select * from Sample2 where id = @id

GO

why does it not append/display the entire resultset?
Thanks,
Stephen
 
G

Greg Burns

You have two result sets is why. (If you where pulling this data with a
datareader, you would have to use the NextResult method to access it).

http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.nextresult

I believe to get the results you want you need to use UNION ALL

Select * from Sample1 where id = @id
UNION ALL
Select * from Sample2 where id = @id

UNION ALL is not as efficient as just UNION (if I'm remembering correctly),
but I think it is requried if you have the exact same data coming from both
selects statements and you want it to be included.

STP? is that short for stored procedure (aka sproc)?

Greg
 
S

Stephen

Greg,
Thanks for the info
stephen

Greg Burns said:
You have two result sets is why. (If you where pulling this data with a
datareader, you would have to use the NextResult method to access it).

http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.nextresult

I believe to get the results you want you need to use UNION ALL

Select * from Sample1 where id = @id
UNION ALL
Select * from Sample2 where id = @id

UNION ALL is not as efficient as just UNION (if I'm remembering correctly),
but I think it is requried if you have the exact same data coming from both
selects statements and you want it to be included.

STP? is that short for stored procedure (aka sproc)?

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top