1.普通存储过程
如数据库有如下存储过程
如数据库有如下存储过程
create proc sp_singleresultset
as
set nocount on
select * from customers
as
set nocount on
select * from customers
然后在IDE服务资源管理器中拖入到dbml中,保存,它就会生成sp_singleresultset的方法,
方法如下:
}
他会自动返回存储过返回的东西。
Linq to Object 代码
var 单结果集存储过程 =
from c in ctx.sp_singleresultset()
select c;
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)
@customerid nchar(5),
@rowcount int output
as
set nocount on
set @rowcount = (select count(*) from customers where customerid = @customerid)
执行
Response.Write(rowcount);
3.多结果集的存储过程
创建一个多结果集的存储过程
create proc [dbo].[sp_multiresultset]
as
set nocount on
select * from customers
select * from employees
as
set nocount on
select * from customers
select * from employees
找到生成的存储过程方法:
}
}
代码测试:
GridView2.DataBind();