1.普通存储过程

如数据库有如下存储过程

create proc sp_singleresultset

as

set nocount on

select * from customers 

然后在IDE服务资源管理器中拖入到dbml中,保存,它就会生成sp_singleresultset的方法,
方法如下:
)(result.ReturnValue));
    }

他会自动返回存储过返回的东西。
Linq to Object 代码

var 单结果集存储过程 =
            
from c in ctx.sp_singleresultset()
           
            select c;

这样就得到了存储过程返回的结果集了

2.带参数的存储过程

  
创建如下存储过程:
create proc [dbo].[sp_withparameter]
@customerid nchar(5),
@rowcount int output
as
set nocount on
set @rowcount = (select count(*from customers where customerid = @customerid)

执行
 rowcount);
        Response.Write(rowcount);

3.多结果集的存储过程


创建一个多结果集的存储过程

create proc [dbo].[sp_multiresultset]
as
set nocount on
select * from customers
select * from employees

找到生成的存储过程方法:
)(result.ReturnValue));
    }
修改为:
 (IMultipleResults)(result.ReturnValue);
    }

代码测试:

 

) select c;

        GridView2.DataBind();

 

相关文章:

  • 2021-10-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-01
  • 2022-12-23
  • 2021-08-30
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-09-26
相关资源
相似解决方案