在数据网格中显示最后五个事务的sql查询问题 [英] problem with the sql query for showing last five transations in data grid

查看:88
本文介绍了在数据网格中显示最后五个事务的sql查询问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string query = "SELECT TOP 5  withdrawamount,depositamount, tdate FROM [transaction] where username='" + txtuser.Text + "' ORDER BY tdate DESC ";




我正在使用此查询来显示数据库中的最后五个事务.此查询正在工作.但不显示最后五个交易...而是显示数据库中的所有交易...

这是怎么回事...前5名




i am using this query to show last five trasaction in data base.. this query is working. but not showing last five transactions ... it is showing all transactions in database...

what is wrong with it... is there something wrong with top 5

推荐答案

像这样写它
Write it like this
select top 5 * from (select withdrawamount,depositamount,tdate from [Transaction] where username=''" + txtuser.txt + "'' order by tdate DESC") AS A


很高兴您能回答您的问题.

但是,您使用的查询存在严重问题.这不是参数化查询.因此,它很容易受到SQL Injection攻击的影响.当您还处于学习过程的早期时,请在Internet上搜索 c#sqlserver参数化查询,并立即开始使用它们,以免坏习惯成为习惯. :)
I am glad you got an answer to your question.

There is however a serious problem with the query that you are using. It is not a parameterized query. Because of this it is open to SQL Injection attacks. While you are still early in your learning process do an internet search for c# sqlserver parameterized queries and start to use them now, before the bad way becomes a habit. :)


这篇关于在数据网格中显示最后五个事务的sql查询问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆