在access中模拟sql server存储过程翻页-钱玉炜
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> 综合其它


在access中模拟sql server存储过程翻页

发表时间:2008/8/21 8:07:56 评论(0) 浏览(5684)  评论 | 加入收藏 | 复制
   
摘 要:在Access中模拟sql server存储过程翻页
正 文:

sql server中翻页存储过程:
Create           PROC blog_GetPagedPosts
(
 @PageIndex int,
 @PageSize int,
 @BlogID   int=0,
 @PostType int=-1,
  @CategoryID int=-1,
  @Hiding     bit =0,
  @Count    int output
       
)
as
DECLARE @PageLowerBound int
DECLARE @PageUpperBound int
SET @PageLowerBound = @PageSize * @PageIndex - @PageSize
SET @PageUpperBound = @PageLowerBound + @PageSize + 1

Create Table #IDs
(
 TempID int IDENTITY (1, 1) NOT NULL,
 EntryID int not null
)
Insert  into #IDs(EntryID)  select DISTINCT [ID] from view_Content  where CategoryID=@CategoryID and blogID=@BlogID   order by [ID] desc
Select  vc.*
FROM   View_Content vc
     INNER JOIN #IDS tmp ON (vc .[ID] = tmp.EntryID)
Where  tmp.TempID > @PageLowerBound
 AND tmp.TempID < @PageUpperBound and vc.Hiding=0
orDER BY tmp.TempID
Select @Count=COUNT(*) FROM  #IDS
Select @Count=COUNT(*) FROM  #IDS
Drop TABLE #IDS
return @Count
GO

 

在Access中由于不支持存储过程,不能建立临时表只能在程序中实现
Access中实现如下,这也是我在myblog Access版中使用的:
public List<DayBook> GetPagedPost(PagedPost p, out int TotalRecords)
        {
            List<DayBook> list = new List<DayBook>();

            using (OleDbConnection conn = GetOleDbConnection())
            {
                StringBuilder sql = new StringBuilder();
                sql.AppendFormat("select  [ID] from blog_Content as p ");//构造查询条件
                if (p.CategoryID > 0)
                {
                    sql.AppendFormat(",blog_Categories AS c, blog_Links AS l Where c.CategoryID=l.CategoryID and (p.ID=l.PostID ) and c.CategoryID={1} and p.BlogID={0}  ",p.BlogID, p.CategoryID);
                }
                else
                {
                    sql.AppendFormat(" where p.blogID={0} ", p.BlogID);
                }
                if (p.PostType != PostType.Undeclared)
                {
                    sql.AppendFormat(" and p.PostType={0} ", (int)p.PostType);
 &


Access软件网交流QQ群(群号:198465573)
 
 相关文章
【Access教程】存储过程入门  【漏蛧尐魚℡  2012/9/6】
【Access教程】vba中调用存储过程  【漏蛧尐魚℡  2012/9/27】
sql2005与sql2008存储过程中 变量使用的一处区别  【smeyou  2013/4/3】
SQL Server 存储过程  【杜超-2号  2013/4/13】
客户端调用Sqlserver存储过程时无记录集返回  【杏林求真  2013/5/8】
常见问答
技术分类
相关资源
文章搜索
关于作者

钱玉炜

文章分类

文章存档

友情链接