11 回答
TA贡献1775条经验 获得超11个赞
用SQL的话,我给你一个存储过程吧,我们一直用..经过无数次考验的..
你在写一个方法来调用这个存储过程就好了..
1 Create proc SP_Page 2 @QueryStr nvarchar(max), 3 @OrderBy nvarchar(100), 4 @PageIndex INT, 5 @PageSize int, 6 @RowCount INT OUTPUT 7 AS 8 BEGIN 9 declare @sqlstring nvarchar(max),@sqlCount int,@pagebegin nvarchar(15),@pageend nvarchar(15) 10 --查询总量,开始页数,结束页数, 11 12 --开始页数 13 set @pagebegin=CAST(((@PageIndex-1)*@PageSize+1) as nvarchar(15)) 14 --结束页数 15 set @pageend=CAST((@PageIndex*@PageSize) as nvarchar(15)) 16 17 SET @sqlstring='select * ,Row_Number()over(order by '+@OrderBy +' desc ) as rowNum from ( '+@QueryStr +' ) as tem ' 18 19 declare @tStr nvarchar(max) 20 set @tStr = 'select @RowCount = Count(0) from ('+@sqlstring+') as counts ' 21 22 EXEC SP_EXECUTESQL @tStr,N'@RowCount INT OUTPUT',@RowCount OUTPUT 23 24 set @sqlstring='select * from ( '+@sqlstring+' ) as endResult where rowNum between '+@pagebegin+' and '+@pageend 25 exec(@sqlstring) 26 END
TA贡献1794条经验 获得超8个赞
DataSet方法实现分页自己调试下:这里的dtSource 是把数据放到一张表里面,number是你分页的时候每页要显示多少条数据.把里面的字段自己对照自己的数据库更改下。注意返回的DataSet.用DataSet中的Tables.Count来作为总的页数.每页做为数据源,其他的就靠你自己了。
public DataSet setDataPage(DataTable dtSource, int number)
{
DataSet dsTarget = new DataSet();
DataTable dts = null;
int j = 0;
if (dtSource.Rows.Count <= number)
{
dts = new DataTable();
dsTarget.Tables.Add(dtSource);
}
else
{
for (int i = 0; i < dtSource.Rows.Count; i++)
{
int a = dtSource.Rows.Count / number;
int b = dtSource.Rows.Count % number;
DataRow dr = null;
if (i <= a * number - 1)
{
if (dts == null)
{
dts = new DataTable();
dts.Columns.Add("LEAVEID");
dts.Columns.Add("USERID");
dts.Columns.Add("BACKID");
dts.Columns.Add("LOCATION");
dts.Columns.Add("CONTENT");
dts.Columns.Add("SIGN");
dts.Columns.Add("TYPE");
dts.Columns.Add("COLOR");
dts.Columns.Add("LEAVETIME");
dts.Columns.Add("FID");
}
dr = dts.NewRow();
dr["LEAVEID"] = dtSource.Rows[i]["LEAVEID"];
dr["USERID"] = dtSource.Rows[i]["USERID"];
dr["BACKID"] = dtSource.Rows[i]["BACKID"];
dr["LOCATION"] = dtSource.Rows[i]["LOCATION"];
dr["CONTENT"] = dtSource.Rows[i]["CONTENT"];
dr["SIGN"] = dtSource.Rows[i]["SIGN"];
dr["TYPE"] = dtSource.Rows[i]["TYPE"];
dr["COLOR"] = dtSource.Rows[i]["COLOR"];
dr["LEAVETIME"] = dtSource.Rows[i]["LEAVETIME"];
dr["FID"] = dtSource.Rows[i]["FID"];
dts.Rows.Add(dr);
j++;
if (j == number)
{
dsTarget.Tables.Add(dts);
j = 0;
dts = null;
}
}
if (i > a * number - 1)
{
if (dts == null)
{
dts = new DataTable();
dts.Columns.Add("LEAVEID");
dts.Columns.Add("USERID");
dts.Columns.Add("BACKID");
dts.Columns.Add("LOCATION");
dts.Columns.Add("CONTENT");
dts.Columns.Add("SIGN");
dts.Columns.Add("TYPE");
dts.Columns.Add("COLOR");
dts.Columns.Add("LEAVETIME");
dts.Columns.Add("FID");
}
dr = dts.NewRow();
dr["LEAVEID"] = dtSource.Rows[i]["LEAVEID"];
dr["USERID"] = dtSource.Rows[i]["USERID"];
dr["BACKID"] = dtSource.Rows[i]["BACKID"];
dr["LOCATION"] = dtSource.Rows[i]["LOCATION"];
dr["CONTENT"] = dtSource.Rows[i]["CONTENT"];
dr["SIGN"] = dtSource.Rows[i]["SIGN"];
dr["TYPE"] = dtSource.Rows[i]["TYPE"];
dr["COLOR"] = dtSource.Rows[i]["COLOR"];
dr["LEAVETIME"] = dtSource.Rows[i]["LEAVETIME"];
dr["FID"] = dtSource.Rows[i]["FID"];
dts.Rows.Add(dr);
if (i == dtSource.Rows.Count - 1)
{
dsTarget.Tables.Add(dts);
}
}
}
}
return dsTarget;
}
TA贡献1911条经验 获得超7个赞
@s_p: 不知道你怎么表现分页的。简单的方法在TextBox两边加个<<或者>>用个超链接控件触发个click事件。里面写简单的处理就ok了.
DataSet st=setDataPage(dtsource,10);
currPage=0;//当前页面。
PreQuery_Click(object sender,EventArgs e)//上一页
{
if(st.Tables.Count<0)
{
//你要执行的操作。
}
if(st.Tables.Count==1)
{
//当前只有一页,你要执行的操作
}
currPage--;//上翻一页。
}
大概就这意思吧。希望对你有帮助。
TA贡献1811条经验 获得超6个赞
un.list = CustomerInfo.GetModel() as List<DbCon_view>;
un.list.skip(i-1*10).take(10)
- 11 回答
- 0 关注
- 359 浏览
添加回答
举报