public static DataTable TotalArticle(int currentPage)
{
SqlConnection conn=dataLink.DbConnet();
SqlCommand cmd=conn.CreateCommand();
cmd.CommandType=CommandType.StoredProcedure;
cmd.CommandText="TotalArticle";
cmd.Parameters.Add("@currentPage",currentPage);
SqlDataAdapter da=new SqlDataAdapter(cmd);
DataSet ds=new DataSet();
try
{
da.Fill(ds);
da.Dispose();
}
catch
{
ds=null;
}
finally
{
conn.Close();
}
return ds.Tables[0];
}currentPage 为1时 这段代码没问题,
但当currentPage为2,3,4...时 就出现:System.NullReferenceException: 未将对象引用设置到对象的实例。
我的分页为每页显示20个记录,哪里错了!难道只能显示第一页,奇怪了,SQL语句 存储过程 没有问题的。
{
SqlConnection conn=dataLink.DbConnet();
SqlCommand cmd=conn.CreateCommand();
cmd.CommandType=CommandType.StoredProcedure;
cmd.CommandText="TotalArticle";
cmd.Parameters.Add("@currentPage",currentPage);
SqlDataAdapter da=new SqlDataAdapter(cmd);
DataSet ds=new DataSet();
try
{
da.Fill(ds);
da.Dispose();
}
catch
{
ds=null;
}
finally
{
conn.Close();
}
return ds.Tables[0];
}currentPage 为1时 这段代码没问题,
但当currentPage为2,3,4...时 就出现:System.NullReferenceException: 未将对象引用设置到对象的实例。
我的分页为每页显示20个记录,哪里错了!难道只能显示第一页,奇怪了,SQL语句 存储过程 没有问题的。
设置端点,检查currentPage.
看上去应该是存储过程的问题.不过既然你很确信.那只能是currentPage不对.
CREATE PROCEDURE TotalArticle
@currentPage int
AS
if (@currentPage=1)
select top 20 ID,Topic,Author,AddTime,ViewNum,Poster,Classic from SundyArticle order by ID desc
else
select top 20 ID,Topic,Author,AddTime,ViewNum,Poster,Classic from SundyArticle where ID not in (' + select top (@currentPage-1)*20 ID from SundyArticle order by ID desc + ') order by ID descGO谢谢楼上的。存储过程是这样的,写错了吗?
看返回记录集是否正确
select top 20 ID,Topic,Author,AddTime,ViewNum,Poster,Classic from SundyArticle where ID not in (' + select top 2*20 ID from SundyArticle order by ID desc + ') order by ID desc
MS这个应该不能执行
这句有问题
@skip int,
@to int
)AS
set rowcount @to
SELECT t1.theID
from(select ROW_NUMBER() OVER(ORDER BY t0.theID) as [Row_NUMBER],t0.theID from dbo.Table_2 AS t0) as t1
where t1.[Row_NUMBER]>@skip
set rowcount 0
RETURN