sql语句在数据库中能查到但用c#中就查不到

sql语句在数据库中能查到但用c#中就查不到,第1张

建议你不要用if(reader。read),换成while吧。if只能执行一次,也就是只能取出read的一个数据。而且我看你在循环中也没有取数据。。在循环里面加上这样一句 XX=readerGetstring(0)。你再试试?还有reader用完了释放,不然有很大的内存消耗。。readerclose();

SQL出错的解决方法是给子查询加别名,如下:

String sqlstr="select top 15 from (select from news order by ID desc) AS A where kind='yes' and ID not in ( select top "+v+" ID from ( select from news order by ID desc ) AS B where kind='yes')";

没有降序排列的原因是将查询条件放置在了带有order by子句的子查询外面,结果又重新排序了,只需改为:

String sqlstr="select top 15 from (select from news where kind='yes' order by ID desc) AS A and ID not in ( select top "+v+" ID from ( select from news where kind='yes' order by ID desc ) AS B)";

描述:sql server 数据库中使用条件查询就可以实现符合查询条件的数据记录显示出来。查询语法为:select from 表名 where 字段名=条件(语法说明:select后面的号代表的是所有字段显示出来。条件出的条件如果为字符型条件需要使用单引号引起来,如果是int类型不用引号),以下以某数据中的一张数据表user_user为例子,分别使用两种查询方式:

1、完整条件查询语法为:select from 表名 where 字段名=条件

查询语句:select from user_user where Dname='管理员'

2、模糊查询条件查询语法为:select from 表名 where 字段名 like '%条件%'  。这里的条件只需要其中一个字符能够与字段中的符合都能够显示出来。

查询语句:select from user_user where Dadd like '%贵%'

以上就是关于sql语句在数据库中能查到但用c#中就查不到全部的内容,包括:sql语句在数据库中能查到但用c#中就查不到、SQL数据库 查询、如何用select语句在SQL数据库中查询符合指定条件的记录等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/9740290.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-01
下一篇 2023-05-01

发表评论

登录后才能评论

评论列表(0条)

保存