无法向存储过程提供参数

无法向存储过程提供参数

本文介绍了无法向存储过程提供参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行相同功能时获取此错误消息:

Getting this error message while executing the same function:

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





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;
    }



添加:

我尝试了ParameterDirection.Output,但由于过程或函数ismovieexists指定的参数过多"而出错.
将变量名称更改为小写.
mymovie类的代码为



ADDITION:

I tried ParameterDirection.Output but got error as "Procedure or function ismovieexists has too many arguments specified."
changed the variable name to lowercase.
code for class mymovie as

public class mymovie
{
   public int movie_id { get; set; }
   public string movie_name { get; set; }
   public int rating { get; set; }
   public int realease_year { get; set; }
   public string starcast { get; set; }
   public string language { get; set; }
   public string display_home { get; set; }
   public string block_status { get; set; }
   public int no_of_copies { get; set; }
   public string movie_category { get; set; }
   public string movie_flag { get; set; }

   public int fetch_total_no_movies()
   {
      mySqlDataAccessLayer obj = new mySqlDataAccessLayer();
      int i = obj.total_no_of_movies();
      return i;
   }
   public int add_movie(string name,int rating,int year,string starcast,string lang,string displayname,string block,int copies,string category,string cd)
   {
      mySqlDataAccessLayer obj = new mySqlDataAccessLayer();
      int i = obj.add_movie(this);
      return i;
   }



在这里我也在做同样的事情,但是代码在gr8上工作..



here too i m doing the same but code is working gr8..

public int loginuser(myadmin objmyadmin)
{
   SqlConnection cn = new SqlConnection(_connectionstring);
   cn.Open();

   SqlCommand cmd = new SqlCommand("valid_login", cn);

   cmd.CommandType = CommandType.StoredProcedure;

   cmd.Parameters.AddWithValue("@username", objmyadmin.admin_name);

   cmd.Parameters.AddWithValue("@password", objmyadmin.password);

   SqlParameter d = new SqlParameter("@d", SqlDbType.Int);

   d.Direction = ParameterDirection.ReturnValue;

   cmd.Parameters.Add(d);
   cmd.ExecuteReader();

   int z = (int)cmd.Parameters["@d"].Value;

   return z;
}


有人帮助我,让我爱不释手"..


"someone plz help me so i cud let my hair grow"..

推荐答案

d.Direction = ParameterDirection.ReturnValue;


如果它是输出参数,则应使用ParameterDirection.Output

如果d 实际上是存储过程的返回数据,则不应将其定义为参数.


If it''s an output parameter, you should use ParameterDirection.Output

If the d is actually the return data of a stored procedure then you shouldn''t define it as a parameter.




这篇关于无法向存储过程提供参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:57