我在调用存储过程时遇到此错误...为什么?
public void InsertVideo()
{
MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["AxWaveConnection"].ToString());
MySqlCommand cmd = new MySqlCommand("InsertVideo", conn);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add(new MySqlParameter("in_youtubevideoid", VideoId));
cmd.Parameters.Add(new MySqlParameter("in_title", Title));
cmd.Parameters.Add(new MySqlParameter("in_rating", ViewCount));
cmd.Parameters.Add(new MySqlParameter("in_viewcount", Rating));
cmd.ExecuteNonQuery();
}
答案 0 :(得分:3)
因为您在致电OPEN
之前忘记了ExecuteNonQuery
连接,请先致电conn.Open()
,
conn.Open();
cmd.ExecuteNonQuery();
答案 1 :(得分:0)
Your complete solution
public void InsertVideo()
{
MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["AxWaveConnection"].ToString());
MySqlCommand cmd = new MySqlCommand("InsertVideo", conn);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
conn.Open()
cmd.Parameters.Add(new MySqlParameter("in_youtubevideoid", VideoId));
cmd.Parameters.Add(new MySqlParameter("in_title", Title));
cmd.Parameters.Add(new MySqlParameter("in_rating", ViewCount));
cmd.Parameters.Add(new MySqlParameter("in_viewcount", Rating));
cmd.ExecuteNonQuery();
}