C# and mysql paging

Asked

Viewed 221 times

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 datagrid datasouce, so far everything right. Now I need to limit the amount of research. Ex:

Select <campos> from tabela limit 0,5

In this Cód sql, the result of the table will be from scratch advancing 5 positions, now I need a loop that changes start to next, ie LIMIT 6.5 AFTERWARD LIMIT 10.5 thus up to 50 records

1 answer

1


One way would be to store 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
}
  • thanks a lot for the answer, but your code is not right, because I do not show the result one by one in the datagrid, it only shows the last result or after the loop ends;

  • @Fabriciosimonealanamendes would be a good opportunity to edit your question and put the code you currently have. The code I entered only makes the select, does not update datagridview none. So, if you show your code I can update the answer.

  • 1

    Thank you very much for your return thanks. It all worked out right here. I used your example, here, updating limit before and after the method that calls the datagrid.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.