C 呼叫SQL Server分頁儲存過程

2021-07-11 14:40:43 字數 1946 閱讀 1639

以sql server2012提供的offset ..rows fetch next ..rows only為例

e.g.

表名:tab1

----------------------------------

id name

1 tblattributegroupdetail

2 tblattributegroup

3 tblattribute

.......

51 tblbritemproperties

52 tblbritem

53 tblbrbusinessrule

54 test

--建立分頁儲存過程 rtabbycondition

use [exampledb]

goif object_id('rtabbycondition','p') is not null

drop procedure rtabbycondition

gocreate procedure [dbo].[rtabbycondition](

@pagecount int=1 --頁數

,@pagesize int=10 --頁顯示記錄數

,@rowcount int=0 output --總記錄數)as

set nocount on;

declare @rows int;

select * from dbo.tab1 order by id offset (@pagecount-1)*@pagesize rows fetch next @pagesize rows only

set @rows=@@rowcount

select @rowcount=count(*) from dbo.tab1;

return @rows

godeclare @i int,@j int

exec @i=[rtabbycondition] @pagecount=6,@pagesize=10,@rowcount=@j output

select @i as "@rowcount",@j as "return_value"

go

顯示結果:

--開啟visual studio—建立專案—選擇【控制台應用程式】

#region directives

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

using system.data;

using system.data.sqlclient;

#endregion

namespace sqlstoredprocedure2

\tname:", thisreader[0], thisreader[1]);

}thisreader.close();

thisconnection.close();

console.writeline("rows:;\treturn_value:;", paraout.value, pararet.value);

console.writeline("program finished,press enter/return to continue:");

console.readline();}}

}

顯示效果:

C 呼叫SQL Server儲存過程

建表 create table sale report sale date datetime not null sale item varchar 2 not null sale money decimal 10,2 not null,primary key sale date,sale item ...

c 呼叫 sqlserver儲存過程

首先建立乙個測試表,結構如下 建立要呼叫的儲存過程 go create procedure test1 pro name varchar 50 mima varchar 50 as begin insert into user table values name,mima end開啟vs 新建控制台...

C 呼叫SQL server儲存過程

控制器方法 提供分頁相關資料 business方法 分頁儲存過程的呼叫 總條數 儲存過程名字 頁數 行數 public listgetlist out int pagecount,string name int pageindex 1,int pagesize 0 new sqlparameter ...