服务器之家:专注于服务器技术及软件下载分享
分类导航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|数据库技术|

服务器之家 - 数据库 - Access - Access 模糊参数 分页查询

Access 模糊参数 分页查询

2021-05-18 21:33Access教程网 Access

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

延伸 · 阅读

精彩推荐