0

我在调用存储过程时遇到此错误...为什么?

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

2 回答 2

3

因为你忘记OPEN了连接,在调用之前,先调用ExecuteNonQueryconn.Open()

conn.Open();
cmd.ExecuteNonQuery();
于 2013-01-28T15:12:10.107 回答
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();
      }
于 2013-06-06T04:05:07.390 回答