自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

在Access中模擬sql server存儲(chǔ)過程翻頁(yè)

數(shù)據(jù)庫(kù)
sql server數(shù)據(jù)庫(kù)是功能性相對(duì)來說完善了的,在數(shù)據(jù)庫(kù)市場(chǎng)中也是領(lǐng)軍的佼佼者,在sql server存儲(chǔ)過程中涉及到的翻頁(yè)操作過程是怎樣的呢?下文中將為大家?guī)碓敿?xì)的解析。

sql server存儲(chǔ)過程的翻頁(yè)是sql server數(shù)據(jù)庫(kù)操作中重要的環(huán)節(jié)之一,下文中就在Access中模擬sql server存儲(chǔ)過程翻頁(yè)的過程,供大家參考。

sql server中翻頁(yè)存儲(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 + 1Create 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() 條件,取其中一頁(yè)
}
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;
}
}

上文中涉及到的代碼比較多,看起來可能大家會(huì)覺得沒有頭緒,所以大家要靜下心來,認(rèn)真閱讀文章中的知識(shí),相信大家都能夠從中收獲。

【編輯推薦】

  1. 如何使用Access數(shù)據(jù)庫(kù)壓縮文件
  2. Access數(shù)據(jù)庫(kù)成功導(dǎo)入Oracle庫(kù)方法
  3. Microsoft SQL Server數(shù)據(jù)庫(kù)庫(kù)名的介紹
  4. SQL Server數(shù)據(jù)庫(kù)簡(jiǎn)體繁體數(shù)據(jù)混用的問題
責(zé)任編輯:迎迎 來源: iTbulo.COM
相關(guān)推薦

2009-03-03 11:51:54

微軟數(shù)據(jù)庫(kù)ACCESS

2010-08-31 15:39:25

DB2存儲(chǔ)過程

2009-08-06 16:44:06

2010-07-15 12:38:14

SQL Server存

2010-11-12 09:18:13

SQL Server存

2010-11-12 09:46:55

Sql Server存

2011-03-24 13:38:47

SQL Server 存儲(chǔ)分頁(yè)

2010-09-14 10:16:57

sql server

2010-09-14 10:36:23

sql server存

2011-03-28 10:46:36

sql server存儲(chǔ)分頁(yè)

2011-07-14 13:38:34

2010-07-05 10:06:51

SQL Server擴(kuò)

2010-07-06 14:06:52

SQL Server存

2010-11-10 13:03:15

SQL Server存

2011-08-15 15:56:31

SQL Server

2010-06-28 09:21:04

SQL Server存

2010-09-06 11:24:32

SQL Server語句

2010-09-03 15:08:03

SQLselect語句

2010-09-02 09:37:36

SQL刪除

2011-08-12 14:51:31

SQL ServerSET NOCOUNT
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)