Access教程 如何模糊参数进行分页查询代码

时间:2021-05-02

本次Access教程,主要给大家介绍代码,下面重点给大家介绍如何模糊参数进行分页查询的教程,接下来一起来看看制作的代码吧!

下面重点给大家介绍如何模糊参数进行分页查询的教程,接下来一起来看看制作的代码吧!

具体代码如下:

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

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章