Click here to Skip to main content
15,921,837 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The code works when I filter the datagridview with researchkey but I couldn't find the correct format code to show the last 5 rows only.I'm using c# and MySQL database , and a buttonClick to get the filter result .
I wish your help .

What I have tried:

I tried this code but it doesn't work :

bs.Filter = "Convert(matricule_number,'System.String') like '" + textBox.Text + "'   and  ORDER BY (id) DESC" ;
Posted
Updated 14-Apr-17 10:11am

Never build an SQL query by concatenating with user inputs, it is named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability.
SQL injection - Wikipedia[^]
SQL Injection[^]
 
Share this answer
 
I'm not an MySQL expert, but maybe this could be useful:
SELECT * FROM mytable LIMIT 100, 5
Takes 5 records beginning from the position of the 100th record.
 
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