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

2022-01-28 21:41:19 字數 4099 閱讀 4396

//**網路,先留個底

1.獲取return返回值

//

儲存過程

//create procedure mysql

//@a int,

//@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"

, sqldbtype.int));

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

intuser_add(user us)

catch

(sqlexception ex)

finally

return

iret;

}

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

public

static

decimal cart_useramount(int

uid)

catch

(sqlexception ex)

finally

return

iret;

}

c# 中呼叫 mysql 儲存過程並傳遞引數和獲取返回值

callablestatement preparedfunc = myconnect.preparecall("");

preparedfunc.registeroutparameter(

1, types.integer);

preparedfunc.setint(

1, anumber);

preparedfunc.execute();

if (preparedfunc.getint(1) == 1

) system.

out.println(anumber +"

is odd");

else

system.

out.println(anumber +"

is even

");

c#操作mysql資料庫的儲存過程

//

mysql過程

//create procedure jugepasswordcorrect(in username varchar(64), in pwd varchar(32))

//begin

//select count(*) from acctable where account=username and password=pwd;

//end;

using

system;

using

system.collections.generic;

using

system.linq;

using

system.text;

using

mysql.data.mysqlclient;

namespace

testmysql2

conn.close();}}

}

其他寫法:

myco = new

mysqlconnection(strconn);

myco.open();

mycomm = new mysqlcommand("

getrecordcount

", myco);

mycomm.commandtype =commandtype.storedprocedure;

mysqlparameter para = new

mysqlparameter;

para[

0].value = "

uinfo";

para[

1].value =strwhere;

mycomm.parameters.addrange(para);

mysqldatareader mydr=mycomm.executereader();

while

(mydr.read())

else

}pagecountlab.text =pagecount.tostring();

}

/*其他:

引數有@開頭的,也有?開頭的.

mysqldataadapter.fill 返回集

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 nbsrkfpxtxejp a int,nbs b int as return a b go sqlconnection conn new sqlconnection configurationmanag...

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

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