欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Access 模糊参数 分页查询

程序员文章站 2022-03-11 15:31:01
复制代码 代码如下: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];