C # and mysql pagination

1

I have a form and a datagrid, in this form I am using a timer to do a search in mysql that fills the datasouce of the datagrid, so far everything is right. Now I need to limit the amount of search. For example:

Select <campos> from tabela limit 0,5

In this sql code, the result of the table will be zero by advancing 5 positions, now I need a loop that changes start to next, ie LIMIT 6,5 AFTER LIMIT 10,5 so up to 50 records

    
asked by anonymous 25.03.2015 / 13:22

1 answer

1

One way would be to save the last requested position and increment it according to the desired number of records:

int numeroDeRegistos = 5;
int totalRegistos = 50;
for(int ultimaPosicao = 0; ultimaPosicao < totalRegistos; ultimaPosicao += numeroRegistos)
{
    // Select <campos> from tabela limit ultimaPosicao,numeroDeRegistos
}
    
25.03.2015 / 14:04