access如何模糊参数进行分页查询代码
2014-10-30来源:

具体代码如下:

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];

更多信息请查看IT技术专栏

推荐信息
Baidu
map