Executing MySqlCommand (StoredProcedure) with output parameter

心已入冬 提交于 2019-12-11 06:03:03

问题


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();

Exception

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)

回答1:


 MySqlCommand command = new MySqlCommand("PredictPaperRankInInterval", con);
 command .CommandType = System.Data.CommandType.StoredProcedure;


来源:https://stackoverflow.com/questions/6319642/executing-mysqlcommand-storedprocedure-with-output-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!