日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

存储过程参数输入输出

發布時間:2025/7/14 编程问答 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 存储过程参数输入输出 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
create procedure proc_page_withtopmax ( @pageIndex int,--頁索引 @pageSize int,--每頁顯示數 @pageCount int output,--總頁數,輸出參數 @totalCount int output--總條數 ) as begin set nocount on;declare @sql nvarchar(1000) set @sql='select top 10 * from tb_testtable where (id> (select max(id) from (select top '+str((@pageIndex-1)*@pageSize)+' id from tb_testtable order by id) as temp)) order by id' execute(@sql)declare @sqlRecordCount nvarchar(1000) --得到總記錄條數的語句 set @sqlRecordCount=N'select @recordCount=count(*) from tb_testtable' declare @recordCount int --保存總記錄條數的變量 exec sp_executesql @sqlRecordCount,N'@recordCount int output',@recordCount outputif( @recordCount % @pageSize = 0) --如果總記錄條數可以被頁大小整除 set @pageCount = @recordCount / @pageSize --總頁數就等于總記錄條數除以頁大小 else --如果總記錄條數不能被頁大小整除 set @pageCount = @recordCount / @pageSize + 1 --總頁數就等于總記錄條數除以頁大小加1set @totalCount = @recordCountset nocount off; end--數據庫中執行該存儲過程 declare @pageCount int, @totalCount intexec proc_page_withtopmax 2,95955,@pageCount output,@totalCount outputselect '總頁數:'+str(@pageCount) select '總條數:'+str(@totalCount)C# 代碼調用該帶輸入輸出參數的分頁存儲過程public static DataSet GetRecordByPage( int pageSize, int pageIndex, out int pageCount, out int totalCount) { DataSet ds = new DataSet(); try { using (SqlConnection conn = new SqlConnection(@"server=;database=data_test;uid=; pwd=;")) { SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.Parameters.Add(new SqlParameter("@pageSize", SqlDbType.Int)); cmd.Parameters.Add(new SqlParameter("@pageIndex", SqlDbType.Int)); SqlParameter param = new SqlParameter("@totalCount", SqlDbType.Int); param.Direction = ParameterDirection.Output; cmd.Parameters.Add(param);SqlParameter param1 = new SqlParameter("@pageCount", SqlDbType.Int); param1.Direction = ParameterDirection.Output; cmd.Parameters.Add(param1);cmd.Parameters[0].Value = pageSize; cmd.Parameters[1].Value = pageIndex; cmd.Parameters[2].Value = 0; cmd.Parameters[3].Value = 0;cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "proc_page_withtopmax"; cmd.CommandTimeout = 180;SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = cmd;DataSet source = new DataSet(); adapter.Fill(ds);object o = cmd.Parameters["@totalCount"].Value; totalCount = (o == null || o == DBNull.Value) ? 0 : System.Convert.ToInt32(o);object b = cmd.Parameters["@pageCount"].Value; pageCount = (b == null || o == DBNull.Value) ? 0 : System.Convert.ToInt32(b); } } catch (SqlException e) { throw e; } return ds; }}

?

?

轉載于:https://www.cnblogs.com/ChineseMoonGod/p/4663717.html

總結

以上是生活随笔為你收集整理的存储过程参数输入输出的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。