使用researchkey过滤datagridview并仅显示最后五行。 [英] Filter datagridview with researchkey and only show the last five rows .
本文介绍了使用researchkey过滤datagridview并仅显示最后五行。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用researchkey过滤datagridview但是我找不到正确的格式代码来显示最后5行时,代码有效。我正在使用c#和MySQL数据库,并使用buttonClick来获取过滤结果。
我希望得到你的帮助。
我的尝试:
我试过这段代码但不起作用:
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" ;
推荐答案
永远不要通过连接用户输入来构建SQL查询,它被命名为SQL注入,它对您的数据库很危险并且容易出错。
名称和程序中的单引号崩溃。如果像Brian O'Conner这样的用户输入可能会使您的应用程序崩溃,那么这是一个SQL注入漏洞。
SQL注入 - 维基百科 [ ^ ]
SQL注入 [ ^ ]
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[^]
我不是MySQL专家,但也许这可能有用:
I'm not an MySQL expert, but maybe this could be useful:
SELECT * FROM mytable LIMIT 100, 5
从第100条记录的位置开始记录5条记录。
Takes 5 records beginning from the position of the 100th record.
这篇关于使用researchkey过滤datagridview并仅显示最后五行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文