1.output引數返回值
1儲存過程中獲得方法:create procedure [dbo].[upinformation](
2 @age int,3
@id bigint output4)
5as6begin
7set nocount on;
8begin
9insert into [information](age )
10values (@age )
11set @id = @@identity
12end
13 end
1 declare @age int2.return過程返回值2declare @id bigint
3 exec [upinformation] @age,@id output
1儲存過程中獲得方法:create procedure [dbo].[upinformation](
2 @age int,3
@id bigint output4)
5as6begin
7set nocount on;
8 if(exists(select * from [shop] where [s_id] =@age ))
9begin
10insert into [information](age ) values (@age )
11set @id =
@@identity
12return 1 — 插入成功返回1
13end
14else
15return 0
— 插入失敗返回0
16 end
1 declare @age int3.select資料集返回值2declare @id bigint
3declare @result bit
4 exec @result = [upinformation] @age ,id output
1儲存過程中獲得方法:(使用臨時表)create procedure [dbo].[upinformation](
2 @id int3)
4as5begin
6set nocount on;
7select id,age from [information]
8 where id = @id
9 go
1c#獲取return返回值create table [dbo].[temp](
2 [id] [bigint] identity(1,1
) not for replication not null,
3 [age] [int
] not null4)
5insert [temp] exec [nb_order_select] @id
6– 這時 temp 就是exec執行select 後的結果集
7 select *from [temp]
8 drop [temp] — 刪除臨時表
1 sqlconnection conn = new sqlconnection(configurationmanager.connectionstrings["c#獲取output輸出引數值connstr
"].tostring());
2conn.open();
3 sqlcommand mycommand = new sqlcommand("
upinformation
", conn); //
儲存過程名字
4 mycommand.commandtype = commandtype.storedprocedure; //
指定型別為儲存過程
5 mycommand.parameters.add(new sqlparameter("@a"
, sqldbtype.int));
6 mycommand.parameters["
@a"].value = 10
;7 mycommand.parameters.add(new sqlparameter("@b"
, sqldbtype.int));
8 mycommand.parameters["
@b"].value = 20
;9 mycommand.parameters.add(new sqlparameter("
@return
", sqldbtype.int));
10 mycommand.parameters["
@return
"].direction =parameterdirection.returnvalue;
11 mycommand.executenonquery(); //
執行儲存過程
12 response.write(mycommand.parameters["
@return
"].value.tostring()); //
取得return的返回值
1 sqlconnection conn = new sqlconnection(configurationmanager.connectionstrings["c#接收儲存過程返回值connstr
"].tostring());
2conn.open();
3 sqlcommand mycommand = new sqlcommand("
upinformation
", conn);
4 mycommand.commandtype =commandtype.storedprocedure;
5 mycommand.parameters.add(new sqlparameter("@a"
, sqldbtype.int));
6 mycommand.parameters["
@a"].value = 20
;7 mycommand.parameters.add(new sqlparameter("@b"
, sqldbtype.int));
8 mycommand.parameters["
@b"].value = 20
;9 mycommand.parameters.add(new sqlparameter("@c"
, sqldbtype.int));
10 mycommand.parameters["
@c"].direction =parameterdirection.output;
11mycommand.executenonquery();
12 response.write(mycommand.parameters["
@c"].value.tostring()); //
指定取得儲存過程的返回值
1c#接收儲存過程的輸出引數public
static
intinformation(user us)225
catch
(sqlexception ex)
2629
finally
3033
return
iret;
34 }
1c#取得結果集public
static
decimal cart_useramount(int
uid)215
catch
(sqlexception ex)
1619
finally
2023
return
iret;
24 }
獲取儲存過程內容 SQL server
查詢儲存過程 內容 select name 儲存過程名稱,definition 儲存過程內容 from sys.sql modules as m inner join sys.all objects as o on m.object id o.object id where o.type p and...
Python如何執行儲存過程,獲取儲存過程返回值
在pathon中如何執行儲存過程呢?可以使用如下方法 儲存過程定義基本如下 alter procedure dbo mysp station varchar 50 sn varchar 50 info varchar 500 output msg varchar 500 output 1.使用ado...
SqlServer獲取儲存過程返回值的例項
sqlserver獲取儲存過程返回值的例項,需要的朋友可以參考一下 1.ouput引數返回值 複製 如下 create procedure dbo nb order insert o buyerid int o id bigint output asbegin set nocount on begi...