我有这个没有参数的存储过程
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `usp_count_rows`(OUT total int)
BEGIN
SELECT COUNT(*)
FROM address_book.persons;
END
我想在 asp.net 页面中使用它。我在后面写了这段代码:
string commandText = "usp_count_rows";
MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["mySqlString"].ConnectionString);
MySqlCommand cmd = null;
try
{
cmd = new MySqlCommand(commandText, conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("total", MySqlDbType.Int32);
cmd.Parameters["total"].Direction = ParameterDirection.Output;
conn.Open();
cmd.ExecuteNonQuery();
int total = (int)cmd.Parameters["?total"].Value;
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Clone();
}
我收到了这个错误信息
指定的演员表无效。
走线
int total = (int)cmd.Parameters["?total"].Value;
我应该怎么做才能使代码正常工作。我想在 aspx 页面中使用结果的另一件事。像这样的东西:总行数:(存储过程的结果)。你有什么建议吗?