解析在Access中模擬sql server存儲(chǔ)過程翻頁_Access數(shù)據(jù)庫教程
推薦:淺析Access數(shù)據(jù)有效性檢查一、 利用字段屬性 1. 數(shù)據(jù)類型屬性 :數(shù)據(jù)類型決定了用戶能保存在此字段中值的種類,如果用戶鍵入的數(shù)據(jù)與字段規(guī)定的類型不一致,Access就不會(huì)存儲(chǔ)該數(shù)據(jù)。如“日期/時(shí)間&rdq
sql server中翻頁存儲(chǔ)過程:
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中由于不支持存儲(chǔ)過程,不能建立臨時(shí)表只能在程序中實(shí)現(xiàn)
Access中實(shí)現(xiàn)如下,這也是我在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 ");//構(gòu)造查詢條件
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;//返回記錄總數(shù)
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]);//構(gòu)造ID in() 條件,取其中一頁
}
else return list; //如沒有記錄返回空表
if(sb.Length>1)
sb.Remove(sb.Length - 1, 1);//刪除最后一個(gè)逗號(hào)
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;
}
}
分享:如何用Access輕松打造圖書管理系統(tǒng)任務(wù):打造個(gè)人圖書管理系統(tǒng) 任務(wù)描述:本文目的是通過Access建立一個(gè)個(gè)人圖書管理系統(tǒng)(可包含音樂CD、數(shù)據(jù)光盤等電子書),幫助我們管理好每一本圖書。這個(gè)數(shù)據(jù)庫可以記錄每本書的基
- Access數(shù)據(jù)庫安全策略之ASP式
- 第N次被ACCESS的關(guān)鍵字涮
- Access中用Jet SQL語句刪除表關(guān)系
- Access報(bào)表打印如何自動(dòng)分頁
- Access完成累計(jì)余額的計(jì)算
- 搭建Access為主的Mdb數(shù)據(jù)庫
- 一句sql更新兩個(gè)表并可更新對(duì)應(yīng)的字段值具體實(shí)現(xiàn)
- MySQL查詢優(yōu)化:連接查詢排序limit(join、order by、limit語句)介紹
- 內(nèi)網(wǎng)ssh/mysql登錄緩慢的解決方法
- 使用準(zhǔn)則進(jìn)行條件查詢--1.4.從窗體中選擇查詢的條件
- 中文Access2000速成教程--1.1 使用“向?qū)А痹O(shè)計(jì)數(shù)據(jù)庫
- 中文Access2000速成教程--1.3 在“設(shè)計(jì)”視圖中設(shè)計(jì)表
- 相關(guān)鏈接:
- 教程說明:
Access數(shù)據(jù)庫教程-解析在Access中模擬sql server存儲(chǔ)過程翻頁
。