Access 模糊分页查询

时间:2014-04-03
简介:数据库|Access模糊分页查询代码如下:  stringsql="SelectCount(ID)AsrcountFromTbProductWHEREclassIDIN

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

TAGS:Access 模糊查询Access分页查询

上一编:Access中批量替换数据库内容的方法

下一编:ACCESS数据库文件压缩和修复方法教程

ab蓝学网|IT技术学习网站
Copyright (C) 2016 www.ablanxue.com, All Rights Reserved.ab蓝学网 IT技术长尾词 New article Hot article