使用输出参数执行MySqlCommand(StoredProcedure)

时间:2011-06-12 01:50:39

标签: c# mysql connector-net

我无法弄清楚如何使用Connector / NET 3.6.5提供的MySQLCommand。基本上这里是我正在使用的代码和运行ExecuteNonQuery时得到的异常。我在这做错了什么?我没有想法:(

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)

1 个答案:

答案 0 :(得分:2)

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