为什么错 该怎么写
string sql = string.Format("select count(*) from SK_Article where ClassID='" + id + "'"order by ArticleId desc");AspNetPager1.RecordCount = DBHelperAccess.GetScalarInt(sql); --------------------编程问答-------------------- 验证id的值是否合法,用SqlCommand + SqlParameter传参 --------------------编程问答-------------------- 没写 order by ArticleId desc 是正确的
就是想排个顺序
ArticleId 可定没错 --------------------编程问答-------------------- string sql = "select count(*) from SK_Article where ClassID='" + id + "'"+"order by ArticleId desc";
--------------------编程问答-------------------- string sql = string.Format("select count(*) from SK_Article where ClassID='" + id + "' order by ArticleId desc"); --------------------编程问答-------------------- string sql = string.Format("select count(*) from SK_Article where ClassID='{0}' ",id);
--------------------编程问答-------------------- count不需要排序 --------------------编程问答-------------------- sql 语句 错了 ,楼上的贴出来了 --------------------编程问答-------------------- 把 id 的单引号去掉
select count(ClassID) as num from SK_Article where ClassID=" + id + " order by ArticleId desc --------------------编程问答-------------------- 这样写string sql = "select count(*) from SK_Article where ClassID='" + id + "'"+"order by ArticleId desc";
后面的 AspNetPager1.RecordCount = DBHelperAccess.GetScalarInt(sql); 就有问题了
--------------------编程问答-------------------- ClassID='" + id + "'"加个空格order --------------------编程问答-------------------- 排序应该不影响 --------------------编程问答-------------------- string sql = string.Format("select count(*) from SK_Article where ClassID='{0}' ",id);
或者
select count(ClassID) as num from SK_Article where ClassID=" + id + " order by ArticleId desc
语句都没有问题
但是 加上 AspNetPager1.RecordCount = DBHelperAccess.GetScalarInt(sql); 就有问题
要不然没有数据
--------------------编程问答-------------------- string sql = string.Format("select count(*) from SK_Article where ClassID='{0}'",id); --------------------编程问答-------------------- DBHelperAccess.GetScalarInt(sql);
这个可能封装有问题,你应该抛出这里面的问题来问。
对于操作数据库推荐一下:CYQ.Data 数据框架,试过方知爽。
--------------------编程问答-------------------- string sql = string.Format("select count(*) from SK_Article where ClassID='" + id + "'"order by ArticleId desc");
不用排序就可以。
Select count(*) From t_User order by User_Id
会报错
ORDER BY 子句中的列 "t_User.User_Id" 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。
有问题请到我的博客留言,我会及时回复的。 --------------------编程问答--------------------
string sql = string.Format("select count(*) from SK_Article where ClassID='" + id + "'"order by ArticleId desc");
大哥。多了个符号
string sql = string.Format("select count(*) from SK_Article where ClassID='" + id + "'order by ArticleId desc");
--------------------编程问答-------------------- 楼主啊!!!仔细点啊!!倒数第二个“去掉就行了!!
补充:.NET技术 , ASP.NET