如何将 vb.net 的输出参数传递给 mysql 存储过程?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13023330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you pass an output parameter from vb.net to a mysql stored procedure?
提问by xpda
I am using the .net connector with mysql 5.5. When I try to call a stored procedure with an "out" parameter, I get the message OUT or INOUT argument 2 for routinenameis not a variable or NEW pseudo-variable in BEFORE triggerat cmd.ExecuteNonQuery().
我在 mysql 5.5 中使用 .net 连接器。当我尝试调用存储过程与“出”的参数,我得到的消息OUT or INOUT argument 2 for routine名称is not a variable or NEW pseudo-variable in BEFORE trigger的cmd.ExecuteNonQuery()。
What is wrong?
怎么了?
vb code:
VB代码:
cmd = New MySqlCommand("call testme(@id, @count)", conn)
cmd.Parameters.AddWithValue("@id", id) ' "id" and "count" are integer variables
cmd.Parameters.AddWithValue("@count", count)
cmd.Parameters("@count").Direction = ParameterDirection.Output
cmd.ExecuteNonQuery()
mysql stored procedure:
mysql存储过程:
CREATE PROCEDURE testme(in taxid integer, out imageDescCount integer)
BEGIN
set imageDescCount = 23;
End
回答by Manoj Savalia
Please try this
请试试这个
Create Stored Procedure in MySQl like
在 MySQl 中创建存储过程,如
DELIMITER $$
DROP PROCEDURE IF EXISTS `tempdb`.`GetCity` $$
CREATE PROCEDURE `tempdb`.`GetCity`
(IN cid INT,
OUT cname VarChar(50)
)
BEGIN
SET cname = (SELECT CityName FROM `City` WHERE CID = cid);
END $$
DELIMITER ;
And Your vb.net code like
你的 vb.net 代码就像
Dim conn As New MySqlConnection()
conn.ConnectionString = "server=localhost;user=root;database=tempdb;port=3306;password=******;"
Dim cmd As New MySqlCommand()
conn.Open()
cmd.Connection = conn
cmd.CommandText = "GetCity"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@cid", "1")
cmd.Parameters("@cid").Direction = ParameterDirection.Input
cmd.Parameters.AddWithValue("@cname", MySqlDbType.String)
cmd.Parameters("@cname").Direction = ParameterDirection.Output
cmd.ExecuteNonQuery()
Console.WriteLine("City Name: " & cmd.Parameters("@cname").Value) //Access Your Output Value
Let me know if you have any problem...
如果您有任何问题,请告诉我...
Thanks
谢谢

