In my C# application, I have a stored procedure which returns some kind of data from the database. The input parameters which I pass to the procedure are start date, end date and a such called “number of lines” parameter. Each line represents an entry in the database. Due to the database call restrictions I can’t pass more than 5000 lines to the procedure per a call. That’s why I want to create a some kind of loop to send 5000 lines, get the corresponding data, then another 5000 lines, etc, until I get an output of lines less than 5000 which would mean that there are no more lines left. Could anybody help me with an idea on how this can be done?
Thanks.
I see only one possible solution for you – you should select your data by primary key. The DBMS will return data ordered by primary key. You should remember key with “maximum value” and at next time you should add condition PK > “maximum value”, where PK is primary key. This will force DBMS to return to you next package of data, size of the package you can regulate by “number of lines” as previously
[EDIT]
I cant provide code sample because of I actually never work with DB in C#. But this fact didnt eliminate that DBMS always sorts table primary key. For example you have table with next columns:
In this table ID is a primary key. So you may do simething like below (pesudo code):
This
SELECTwould return to you “first” 5000 rows from table. “first” means first rows in index by primary key. To select next 5000 rows you should do:This select will return “next” 5000 rows due
ID > maxIDcondition.