0

I Got some data from database with the following command:

string SearchSql = string.Format("SELECT ACCOUNT, PASSWORD, TOTALIP, FINISHDATE FROM tbl_LOL_ACCOUNT JOIN tbl_LOL_REGION ON tbl_LOL_ACCOUNT.RegionID = tbl_LOL_REGION.ID WHERE REGIONSHORT = '{0}' AND MAXIP = '{1}' LIMIT {2}", regionComboBox.SelectedItem, IPComboBox.SelectedItem), amountTxt.Text);

It gets accounts as many as the amountTxt.Text value. (LIMIT {2}) That's not a problem, after getting these data, I entered them to my data grid view, as you can see in the picture: enter image description here

All of that are good! The problem is here: I want to when i click the same button which send request of SQL command to get the next rows after these ones! Logically, when i try to use the same command, it returns the same result! What about getting next to them?

If there are some strings need to be add to the command will be good, if not, then I hope someone can help me with a way to perform that!

Thanks!

GameHackerPM
  • 97
  • 1
  • 10
  • Possibly look into using OFFSET/Fetch http://dbadiaries.com/new-t-sql-features-in-sql-server-2012-offset-and-fetch – Bubba Jan 23 '17 at 20:53

1 Answers1

1

I think using limit is not a correct way to go here. As limit simply limits number of rows you get as an answer. You can appropriate below code to your needs. Simply specify min and max. For example if you want to get from row 10 to row 50. And apply whatever condition you need.

select * from (select Row_Number() over (order by ID) as RowIndex, * from 'TableName' where 'Use whatever you want' ) as Sub Where Sub.RowIndex >= MinRowNo and Sub.RowIndex <= MaxRowNo;