向存储过程提供参数时出错

时间:2022-04-12 20:11:09

I am getting the following error while supplying parameters to a stored procedure:

我在向存储过程提供参数时收到以下错误:

Procedure or function 'ismovieexists' expects parameter '@movie_name', which was not supplied

过程或函数'ismovieexists'期望参数'@movie_name',它未提供

and the same error message for the procedure insert_values_in_movie_master..

以及过程insert_values_in_movie_master的相同错误消息..

public int add_movie(mymovie objmymovie)
{ 
    SqlConnection cn = new SqlConnection(_connectionstring);
    cn.Open();
    //SqlDataReader dr;
    SqlCommand cmd = new SqlCommand("ismovieexists", cn);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@movie_name", objmymovie.MOVIE_NAME);
    SqlParameter d = new SqlParameter("@d", SqlDbType.Int);
    d.Direction = ParameterDirection.ReturnValue;
    cmd.Parameters.Add(d);
    cmd.ExecuteReader();
    int i = (int)cmd.Parameters["@d"].Value;

    if (i == 0)
    {
        SqlCommand cmd1 = new SqlCommand();

        cmd1.Connection = cn;
        cmd1.CommandType = CommandType.StoredProcedure;
        cmd1.CommandText = "insert_values_in_movie_master";
        cmd1.Parameters.AddWithValue("@movie_name", objmymovie.MOVIE_NAME);
        cmd1.Parameters.AddWithValue("@rating", objmymovie.RATING);
        cmd1.Parameters.AddWithValue("@realease_year", objmymovie.REALEASE_YEAR);
        cmd1.Parameters.AddWithValue("@starcast", objmymovie.STARCAST);
        cmd1.Parameters.AddWithValue("@language", objmymovie.LANGUAGE);
        cmd1.Parameters.AddWithValue("@display_home", objmymovie.DISPLAY_HOME);
        cmd1.Parameters.AddWithValue("@block_status", objmymovie.BLOCK_STATUS);
        cmd1.Parameters.AddWithValue("@no_of_copies", objmymovie.no_of_copies);
        cmd1.Parameters.AddWithValue("@MOVIE_category", objmymovie.MOVIE_category);
        cmd1.Parameters.AddWithValue("@MOVIE_flag", objmymovie.MOVIE_FLAG);
        cmd1.ExecuteNonQuery();
        return i;
    }
    else
        return 1;
}

1 个解决方案

#1


2  

Does the parameter @Movie_Name exist in your Stored Procedures? If the parameter does exist it's likely that you are not passing a value to objmymovie.MOVIE_NAME

参数@Movie_Name是否存在于您的存储过程中?如果参数确实存在,则可能是您没有将值传递给objmymovie.MOVIE_NAME

#1


2  

Does the parameter @Movie_Name exist in your Stored Procedures? If the parameter does exist it's likely that you are not passing a value to objmymovie.MOVIE_NAME

参数@Movie_Name是否存在于您的存储过程中?如果参数确实存在,则可能是您没有将值传递给objmymovie.MOVIE_NAME