网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > 数据库 > Access教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
数据库:数据库教程,数据库技巧,Oracle教程,MySQL教程,Sybase教程,Access教程,DB2教程,数据库安全,数据库文摘
本月文章推荐
.ACCESS改为SQL需要注意哪几个地方.
.Access 2007通过查询来计算累计余.
.Microsoft Access秘密、技巧和陷.
.堵住电脑中的Access漏洞 拒绝恶意.
.ACCESS统计不重复记录个数问题.
.将使用Access的论坛迁移到SqLSer.
.在VB中压缩ACCESS数据库.
.在设计视图中Access允许的九种数.
.MS SQL Server和Access分别取得随.
.sql server与excel、access数据互.
.关于Access数据表中的Size字段In.
.将Access数据转换为XML格式.
.在ACCESS中LIKE的用法.
.SQL SERVER与ACCESS、EXCEL的数据.
.Microsoft Access技巧及陷阱讲解.
.带你深入了解Access数据库的4种安.
.使用SQL Server数据转换服务升迁.
.Access中的模糊查询.
.疑难解答:怎样使用Access数据库.
.在Access2007表中同时显示明细、.

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

发表日期:2006-6-11


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);
                }
                sql.Append(" order by p.[DateUpdated] desc");
               // NetDiskContext.Current.Context.Response.Write(sql.ToString());
                //NetDiskContext.Current.Context.Response.End();
                OleDbCommand MyComm = new OleDbCommand(sql.ToString(), conn);
                List<int> IDs = new List<int>(); //获取主题ID列表
                conn.Open();
                using (OleDbDataReader dr = MyComm.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        IDs.Add((int)dr[0]);
                   
                    }
                }
              
                TotalRecords=IDs.Count;//返回记录总数
                if (TotalRecords < 1)
                    return list;
                int pageLowerBound = p.PageSize * p.PageIndex - p.PageSize;//记录索引
                int pageUpperBound = pageLowerBound + p.PageSize ;
                StringBuilder sb = new StringBuilder();
                if (TotalRecords >= pageLowerBound)
                    for (int i = pageLowerBound; i < TotalRecords && i < pageUpperBound; i++)
                    {
                        sb.AppendFormat("{0},", IDs[i]);//构造ID in() 条件,取其中一页
                    }
                else return list; //如没有记录返回空表
                if(sb.Length>1)
                sb.Remove(sb.Length - 1, 1);//删除最后一个逗号
            MyComm.CommandText = string.Format("SELECT b.* , c.Account as Account FROM blog_Content b, Blog_Config  c where b.BlogID=c.BlogID and b.[ID] in ({0}) order by b.dateadded desc", sb.ToString());
                using (OleDbDataReader dr = MyComm.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        list.Add(DataHelp.LoadDayBook(dr));
                    }
                }
                return list;
            }
         }

 

 转帖请注明出处..深Q

上一篇:sql server 转 access 笔记 人气:8883
下一篇:在ACCESS中LIKE的用法 人气:13043
浏览全部Access的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐