晒晒我的通用数据访问层

发表于:2011-7-07 10:05

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:李奇峰    来源:51Testing软件测试网采编

  C#调用代码

  1. public bool UpdateProduct(Product product)  
  2. {  
  3.     return (FishBLLHelper.CallSpExecuteNonQuery("UpdateProduct", product) > 0);  
  4. }

  存储过程-获取商品列表,支持分页

  1. create procedure [dbo].[GetProductByCategoryId](  
  2.     @CategoryID int,  
  3.     @PageIndex int = 0,  
  4.     @PageSize int = 20,  
  5.     @TotalRecords int output  
  6. )  
  7. as 
  8. begin  
  9.      
  10. declare @ResultTable table  
  11. (  
  12.     RowIndex int,  
  13.     ProductID int,  
  14.     ProductName nvarchar(50),  
  15.     CategoryID int,  
  16.     Unit nvarchar(10),  
  17.     UnitPrice money,  
  18.     Quantity int 
  19. );  
  20.      
  21. insert into @ResultTable  
  22. select row_number() over (order by ProductID asc) as RowIndex,  
  23.        p.ProductID, p.ProductName, p.CategoryID, p.Unit, p.UnitPrice, p.Quantity  
  24. from   Products as p  
  25. where CategoryID = @CategoryID;  
  26.        
  27. select  @TotalRecords = count(*) from  @ResultTable;  
  28.      
  29. select *  
  30. from   @ResultTable  
  31. where  RowIndex > (@PageSize * @PageIndex) and RowIndex <= (@PageSize * (@PageIndex+1));  
  32.      
  33. end;

  C#调用代码

  1. public List<Product> GetProductByCategoryId(int categoryId, ref int pageIndex, int pageSize, out int recCount)  
  2. {  
  3.     return FishBLLHelper.CallSpGetDataItemListPaged<Product>("GetProductByCategoryId",  
  4.    ref pageIndex, pageSize, out recCount, categoryId);  
  5. }

42/4<1234>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号