Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


If i have one stored procedure,which is not under my control i.e server may be at other place returning thousand records. Now i want to bind dataset by using this stored procedure but do not want total thousand records instead of i want only hundred records. so my problem is with out modifying stored procedure...
Posted
Comments
Richard C Bishop 13-Aug-13 14:46pm    
If you cannot alter the stored procedure, your only choice is to alter the data that is returned.
ZurdoDev 13-Aug-13 15:05pm    
I think (I hope) they understand that and are looking for options as to how to do that. I suppose using a DataTable would be one way.
virusstorm 13-Aug-13 15:21pm    
No matter what you do, the stored procedure will execute and all of the results will come back to your code. So you will be using memory and CPU on data that you don't want. You can filter the data when it come back (using LINQ is one way). The only way to truly prevent the data from coming back is to modify the stored procedure.

1 solution

I don't think you are going to find a good option without getting into something you do not want to get into. Such as returning a truncating the response stream or something really off the wall that proably wouldn't even work anyway. I'm not saying that is possible, but to reduce the response size coming back, you'd have to do something like that without having access to the sproc itself. I don't know of anyway to limit the size based on the connection string or execute method for the sproc. But there may be a way. But it would be odd.

I only see a couple of options here.

1.) Can you write another sproc to return only the first 100 from the first sproc? That might be better than having a million records come back to the application. The first sproc will select a million records, but the second one would reduce it before returning it to your app. But I suspect you cannot, as it doesn't sound like you have any control over the database.

2.) If you cannot modify the orgional sproc, there is no way to limit what it returns unless the sproc as parameters that you can pass in to control it. Are there any parameters you might be able to control to reduce the number of records? If not, maybe ask the DBA to modify the sproc to allow you to send in a param that the sproc could use to return a given TOP count... or make a second copy of that sproc for your needs and limit it. But if they will not or you cannot ask them to... then maybe there is a third option...

3.) One last option. Jsut don't use the sproc! If you only need to return 100 records, maybe you could do this without the sproc. The sproc is faster, but a SQL Query might be ok with only 100 records. Of course that assumes a lot. But I would consider it if I had no option other than returning thousands of records. Can you determine how the sproc works or do you have the ability and write a query yourself?

Unless there are options outside of my experiance, which I am sure there are, I cannot think of any other options. It is an odd requirement really. Hopefully you can find a better way.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900