C 獲取儲存過程返回值和輸出引數值的方法

2022-09-29 17:36:13 字數 2259 閱讀 7542

1.獲取return返回值

複製** **如下:

//儲存過程

//create procedure mysql

//   &nbsrkfpxtxejp; @a int,

//   &nbs @b int

//as

//     return @a + @b

//go

sqlconnection conn = new sqlconnection(configurationmanager.connectionstrings["localsqlserver"].tostring());

conn.open();

sqlcommand mycommand = new sqlcommand("mysql", conn);

mycommand.commandtype = commandtype.storedprocedure;

mycommand.parameters.add(new sqlparameter("@a", sqld

mycommand.parameters["@a"].value = 10;

mycommand.parameters.add(new sqlparameter("@b", sqldbtype.int));

mycommand.parameters["@b"].value = 20;

mycommand.parameters.add(new sqlparameter("@return", sqldbtype.int));

mycommand.parameters["@return"].direction = parameterdirection.returnvalue;

mycommand.executenonquery();

response.write(mycommand.parameters["@return"].value.tostring());

2.獲取output輸出引數值

複製** **如下:

//儲存過程

//create procedure mysql

//     @a int,

//     @b int,

//     @c int output

//as

//     set @c = @a + @b

//go

sqlconnection conn = new sqlconnection(configurationmanager.connectionstrings["localsqlserver"].tostring());

conn.open();

sqlcommand mycommand = new sqlcommand("mysql", conn);

mycommand.commandtype = commandtype.storedprocedure;

mycommand.parameters.add(new sqlparameter("@a", sqldbtype.int));

mycommand.parameters["@a"].value = 20;

mycommand.parameters.add(new sqlparameter("@b", sqldbtype.int));

mycommand.parameters["@b"].value = 20;

mycommand.parameters.add(new sqlparameter("@c", sqldbtype.int));

mycommand.parameters["@c"].direction = parameterdirection.output;

mycommand.executenonquery();

response.write(mycommand.parameters["@c"].value.tostring());

c#接收儲存過程返回值:

複製** **如下:

public static int user_add(user us)

catch (sqlexception ex)

finally

return iret;

}c#接收儲存過程輸出引數:

複製** **如下:

public static decimal cart_useramount(int uid)

catch (sqlexception ex)

finally

return iret;

}本文標題: c#獲取儲存過程返回值和輸出引數值的方法

本文位址:

C 獲取儲存過程返回值和輸出引數值

1.獲取return返回值 程式 儲存過程 create procedure mysql a int,b int as return a b go sqlconnection conn new sqlconnection configurationmanager.connectionstrings ...

C 獲取儲存過程返回值和輸出引數值的方法

網路,先留個底 1.獲取return返回值 儲存過程 create procedure mysql a int,b int as return a b go sqlconnection conn new sqlconnection configurationmanager.connectionstr...

SqlServer獲取儲存過程返回值的例項

sqlserver獲取儲存過程返回值的例項,需要的朋友可以參考一下 1.ouput引數返回值 複製 如下 create procedure dbo nb order insert o buyerid int o id bigint output asbegin set nocount on begi...