使用输出参数执行 MySqlCommand (StoredProcedure) [英] Executing MySqlCommand (StoredProcedure) with output parameter
本文介绍了使用输出参数执行 MySqlCommand (StoredProcedure)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道如何使用由 Connector/NET 3.6.5 提供的 MySQLCommand.基本上这里是我使用的代码和运行 ExecuteNonQuery 时得到的异常.我在这里做错了什么?我没有任何想法了:(
I can't figure out how to use MySQLCommand provided by Connector/NET 3.6.5. Basically here is the code I'm using and exception I get when I run ExecuteNonQuery. What am I doing wrong here? I have no ideas left :(
var connection = GetConnection();
connection.Open();
var command = new MySqlCommand("PredictPaperRankInInterval", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new MySqlParameter("p_journalId", SqlDbType.VarChar) { Value = "test" });
command.Parameters.Add(new MySqlParameter("p_publishDate", SqlDbType.DateTime) { Value = paper.PublishDate });
command.Parameters.Add(new MySqlParameter("p_intervalInDays", SqlDbType.Int) { Value = 7 });
command.Parameters.Add(new MySqlParameter("p_viewsCount", SqlDbType.Int) { Value = paper.ViewsCount });
var rank = new MySqlParameter("p_rank", SqlDbType.Int) { Direction = ParameterDirection.Output };
command.Parameters.Add(rank);
command.ExecuteNonQuery();
异常
Input string was not in a correct format.
DDL
CREATE PROCEDURE `PredictPaperRankInInterval`(IN p_journalId VARCHAR(32),
IN p_publishDate DATETIME,
IN p_intervalInDays INT,
IN p_viewsCount INT,
OUT p_rank INT)
推荐答案
MySqlCommand command = new MySqlCommand("PredictPaperRankInInterval", con);
command .CommandType = System.Data.CommandType.StoredProcedure;
这篇关于使用输出参数执行 MySqlCommand (StoredProcedure)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文