在向存储过程提供参数时,我收到以下错误:
过程或函数'ismovieexists'期望参数'@movie_name',未提供
和过程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;
}
答案 0 :(得分:2)
您的存储过程中是否存在参数@Movie_Name?如果参数确实存在,则可能是您没有将值传递给objmymovie.MOVIE_NAME