Access 模糊参数 分页查询
程序员文章站
2022-06-22 17:07:57
复制代码 代码如下:string sql = "select count(id) as rcount from tbproduct where classid in(" + ids + ") and...
复制代码 代码如下:
string sql = "select count(id) as rcount from tbproduct where classid in(" + ids + ") and productname like '%'+@productname+'%'";
oledbparameter[] sps = new oledbparameter[1];
sps[0] = accessdb.createparameter("@productname", oledbtype.varchar, productname, 50, parameterdirection.input);
int resultcount = (int)accessdb.executescalar(sql, sps);
recordcount = resultcount;
if (resultcount >= 0)
{
if ((resultcount % pagesize) == 0)
{
pagecount = resultcount / pagesize;
}
else
{
pagecount = (resultcount / pagesize) + 1;
}
if (pageindex == 1)
{
sql = "select top " + pagesize.tostring() + " * from tbproduct where classid in(" + ids + ") and productname like '%'+@productname+'%' order by id desc";
}
else
{
int minrecord = (pageindex - 1) * pagesize;
sql = "select top " + pagesize.tostring() + " * from tbproduct where id not in(select id from (select top " + minrecord.tostring() + " id from tbproduct where classid in(" + ids + ") and productname like '%'+@productname+'%' order by id desc )tema) and classid in(" + ids + ") and productname like '%'+@productname+'%' order by id desc";
}
}
else
{
pagecount = 0;
}
return accessdb.executedataset(sql, sps).tables[0];
上一篇: 努尔哈赤是如何建立后金的?实力有多强劲?