过程或函数需要未提供的参数 ' [英] Procedure or function expects parameter ' which is not supplied

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

问题描述

你好朋友,我面临一个将数据加载到网格视图的问题.

hello friends i face one issue for load the data to grid view.

页面加载事件调用像 loaddata() 这样的一个方法,我在里面写代码

the page load event call the one method like loaddata() inside i write the code this

  using (SqlConnection Sqlcon = new SqlConnection(strCon))
        {
            using (SqlCommand cmd = new SqlCommand())
            {
                Sqlcon.Open();
                cmd.Connection = Sqlcon;

                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "SP_Marketing";
                //cmd.Parameters.Add(new SqlParameter("@Sno", (object) ?? null.Value));
                cmd.Parameters.Add(new SqlParameter("@pvchAction", SqlDbType.VarChar,50));
                cmd.Parameters["@pvchAction"].Value = "select";
                cmd.Parameters.Add("@pIntErrDescOut", SqlDbType.Int).Direction = ParameterDirection.Output;

                SqlAda = new SqlDataAdapter(cmd);
                ds = new DataSet();
                SqlAda.Fill(ds);
                GridViewSample.DataSource = ds;
                GridViewSample.DataBind();
            }
        }

在 sqlada 中查找存储过程记录时遇到错误,例如过程或函数需要参数 @dateemailed 未提供"

the find the store procedure records in sqlada caught error like"Procedure or function expects parameter @dateemailed which is not supplied"

ALTER PROCEDURE SP_Marketing          
(            
 @Sno   int  =0,            
 @DateEmailed datetime,            
 @DateResponded datetime,            
 @EmailRep  varchar(100)=null,    
 @Type   varchar(100)=null,    
 @Country  varchar(100)=null,    
 @State  varchar(100)=null,    
 @NameoftheCompany varchar(100)=null,    
 @website  varchar(100)=null,    
 @FirstName  varchar(100)=null,    
 @LastName  varchar(100)=null,    
 @Title   varchar(100)=null,    
 @Email   varchar(100)=null,    
 @Telephone  varchar(100)=null,    
 @Capabilities varchar(100)=null,    
 @Focus   varchar(100)=null,    
 @pvchCreatedBy  varchar(100)=null,            
 @pvchAction   varchar(50)=null,            
 @pIntErrDescOut  int output    
)            
AS            
 BEGIN            

   if(@pvchAction='select')         
    begin    
     SELECT sno,Dateemailed,dateresponded,emailrep,[type],country,[state],     , nameofthecompany,website,Firstname,Lastname,Title,email,telephone,
capabilities,  Focus FROM Emailmarketing  WHERE active=1  
  end


else if(@pvchAction='insert')    
  begin    
  INSERT INTO EmailMarketing(DateEmailed,DateResponded,EmailRep,[Type],    
  Country,[State],NameoftheCompany,website,FirstName,LastName,Title,Email,Telephone,Capabilities,Focus,Createdby,CreatedDt,Active)VALUES(@DateEmailed,@DateResponded,@EmailRep,@Type,    
  @Country,@State,@NameoftheCompany,@website,@FirstName,@LastName,@Title,@Email,@Telephone,@Capabilities,@Focus,@pvchCreatedBy,GETDATE(),1);    

  end    
  else if(@pvchAction='update')    
  begin    
  UPDATE EmailMarketing SET DateEmailed=@DateEmailed,DateResponded=@DateResponded,EmailRep=@EmailRep,[Type]=@Type,Country=@Country,[State]=@State,NameoftheCompany=@NameoftheCompany,website=@website,FirstName=@FirstName,LastName=@LastName,Title=@Title,Email=@Email,Telephone=@Telephone,Capabilities=@Capabilities,Focus=@Focus,Updatedby=@pvchCreatedBy,UpdatedDt=GETDATE()    
  WHERE Sno=@Sno;    
  end    
  else if(@pvchAction='delete')    
  begin    
  UPDATE   EmailMarketing SET Active=@pvchAction WHERE Sno=@Sno;    
  end    

    IF (@@ERROR <> 0)             
   BEGIN             
  SET @pIntErrDescOut = 1            
   END            
  ELSE            
   BEGIN            
  SET @pIntErrDescOut = 0            
   END     



END

推荐答案

以下参数在您的存储过程中没有默认值:

The following parameters don't have default values in your stored proc:

@DateEmailed datetime,            
@DateResponded datetime, 

所以你总是需要在代码中提供这些值:

So you always need to provide those values in the code:

cmd.Parameters.Add(new SqlParameter("@DateEmailed", SqlDbType.DateTime));
cmd.Parameters["@DateEmailed"].Value = DateTime.Now; // Provide your value here
cmd.Parameters.Add(new SqlParameter("@DateResponded", SqlDbType.DateTime));
cmd.Parameters["@DateResponded"].Value = DateTime.Now; // Provide your value here

这篇关于过程或函数需要未提供的参数 '的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆