//执行存储过程方法
public DataTable ExecProcReturn(string strName, SqlParameter[] sqlParas)
{
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["Myconnection"].ToString());
conn.Open();
using (SqlCommand com = new SqlCommand())
{
com.Connection = conn;
com.CommandText = strName;
com.CommandType = CommandType.StoredProcedure;
if (sqlParas != null && sqlParas.Length > 0)
{
foreach (SqlParameter sqlPara in sqlParas)
{
com.Parameters.Add(sqlPara);
}
}
SqlDataAdapter da = new SqlDataAdapter(com);
da.Fill(dt);//调试此处提示TOP N 值不得为负
}
conn.Close();
return dt;
}sql如下:
create proc xp_Page
@PageIndex int
as
declare @PageSize int
set @PageSize=5
if(@PageIndex=1)
begin
select top (@PageSize) [DiaryTitle],[DiaryTime],[DiaryAuthor] from [Diary] order by [DiaryID] desc
end
else
begin
select top (@PageSize) [DiaryTitle],[DiaryTime],[DiaryAuthor] from [Diary] where [DiaryId] not in
(select top ((@PageIndex-1)*(@PageSize)) [DiaryId] from [Diary] order by [DiaryID] desc)
order by [DiaryId] desc
end这是什么原因啊,求解,谢谢!
public DataTable ExecProcReturn(string strName, SqlParameter[] sqlParas)
{
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["Myconnection"].ToString());
conn.Open();
using (SqlCommand com = new SqlCommand())
{
com.Connection = conn;
com.CommandText = strName;
com.CommandType = CommandType.StoredProcedure;
if (sqlParas != null && sqlParas.Length > 0)
{
foreach (SqlParameter sqlPara in sqlParas)
{
com.Parameters.Add(sqlPara);
}
}
SqlDataAdapter da = new SqlDataAdapter(com);
da.Fill(dt);//调试此处提示TOP N 值不得为负
}
conn.Close();
return dt;
}sql如下:
create proc xp_Page
@PageIndex int
as
declare @PageSize int
set @PageSize=5
if(@PageIndex=1)
begin
select top (@PageSize) [DiaryTitle],[DiaryTime],[DiaryAuthor] from [Diary] order by [DiaryID] desc
end
else
begin
select top (@PageSize) [DiaryTitle],[DiaryTime],[DiaryAuthor] from [Diary] where [DiaryId] not in
(select top ((@PageIndex-1)*(@PageSize)) [DiaryId] from [Diary] order by [DiaryID] desc)
order by [DiaryId] desc
end这是什么原因啊,求解,谢谢!
解决方案 »
- GRIDVIEW中放了个TEXTBOX,如何获取TEXTBOX的光标所在的行号和列好,
- |M| 幕白兄还是没有办法,请你看看
- 关于Menu控件的子项样式定义.
- 請教關於Cache的問題 。
- 关于datagrid 表的问题
- 关于网页里Meta的问题?
- 帮忙~ 我已提交表单就数据没有帮定到实列
- 求助!关于ASP。NET上传到服务器上出的问题!请帮帮偶!
- 有1万个节点的树结构用iewebcontrols的treeview控件做是否可以,几百人同时访问可以吗?主要是担心性能不行。
- 怎样给Table中动态添加的linkButton添加事件?
- 触发器问题
- gridview 导出excel 迅雷下载时问题 急求解决方法!
这里为付数了
如果传过来0的话
(@startIndex int,
@endIndex int)
asbegin
with temptbl as (
SELECT ROW_NUMBER() OVER (ORDER BY DiaryId desc)AS Row, O.[DiaryTitle],O.[DiaryTime],O.[DiaryAuthor] from Diary )
SELECT * FROM temptbl where Row between @startIndex and @endIndex
end
SET @pagenum = 2
SET @pagesize = 3
SELECT *
FROM (SELECT ROW_NUMBER() OVER(ORDER BY newsid DESC) AS rownum,
newsid, topic, hits
FROM news) AS D
WHERE rownum BETWEEN (@pagenum-1)*@pagesize+1 AND @pagenum*@pagesize
ORDER BY newsid DESC