gridview分页代码(可提高分页速度)
internal static datatable datareadertodatatable(string squery, int istart, int iend)
{
datatable schematable = null;
datatable dt = null;
sqlcommand cmdsql;
sqldatareader dr = null;
sqlconnection conn = null;
long icount = 0;
try
{
//打开数据库教程连接,执行datareader
conn = new sqlconnection(connstring);
conn.open();
cmdsql = new sqlcommand(squery, conn);
dr = cmdsql.executereader(commandbehavior.closeconnection);
schematable = dr.getschematable();
dt = new datatable();//get the schema of tables columns and its types, and load the same into datatable.
for (int i = 0; i <= schematable.rows.count - 1; i++)
{
datarow drow = schematable.rows[i];
datacolumn column = new datacolumn();
column.datatype = system.type.gettype(drow["datatype"].tostring());
column.allowdbnull = (drow["allowdbnull"].tostring() == "true" ? true : false);
column.columnname = drow["columnname"].tostring();
column.caption = drow["columnname"].tostring();
dt.columns.add(column);
//more datatable property can be added as required.
}
if (istart == 0) istart = 1;
if (iend == 0) iend = 1;
icount = 1;//loop the reader which is executed till the start and variable,
//fetch and add the rows one by one to data table till the end count is reached.
// exit the loop and return datable.
while (dr.read())
{
if (icount >= istart && icount <= iend)
{
datarow drow = dt.newrow();
for (int i = 0; i <= dr.fieldcount - 1; i++)
{
drow[i] = dr.getvalue(i);
}
dt.rows.add(drow);
}
else if (icount > iend)
{
break;
}
icount = icount + 1;
}
}
catch (systemexception ex)
{
throw ex;
}
finally
{
conn.close();
conn.dispose();
schematable.dispose();
dr.close();
dr.dispose();
}
return dt;
}
在后台绑定到gridview的方法如下:
private void binddata(int pageindex)
{
int startrow;
int endrow;startrow = (pageindex * grdemployee.pagesize) +1;
endrow= startrow + grdemployee.pagesize -1;
grdemployee.datasource= custompaging.class.common.datareadertodatatable(selectquery,startrow,endrow);
grdemployee.databind();
}
1、执行datareader
2、从我们规定的开始的位置执行datareader
3、执行并得到数据记录
4、将数据记录放到datatable数据集中
5、结束datareader
6、返回datatable数据集。
我的博物馆故事 官方安卓版v1.61.2
我的博物馆故事是一款以消除为主题的经营养成类手游,在这里玩家
专业模拟飞行10 手机版v12.2.4
专业模拟飞行10安卓版是一款飞行休闲手游,顶尖的物理飞行引擎
动物起义战斗模拟器二琳同款 最新版v4.1.1
动物起义战斗模拟器是一个非常有趣的模拟类游戏,玩家可以召唤各
迷你世界七周年 安卓手机版v1.43.0
迷你世界7周年是一款由《迷你世界》官方推出的庆祝特别版本,在
劫后公司无限资源版 v1.0.5.1
劫后公司内置菜单版是游戏的破解版本,在该版本中为玩家提供了内