Procedure expects parameter which was not supplied

后端 未结 12 1455

I\'m getting the error when accessing a Stored Procedure in SQL Server

Server Error in \'/\' Application.
Procedure or function \'ColumnSeek\' expects parame         


        
相关标签:
12条回答
  • 2020-12-02 18:37

    I came across this error today when null values were passed to my stored procedure's parameters. I was able easily fix by altering the stored procedure by adding default value = null.

    0 讨论(0)
  • 2020-12-02 18:39

    For my case, I had to pass DBNULL.Value(using if else condition) from code for stored procedures parameter that are not defined null but value is null.

    0 讨论(0)
  • 2020-12-02 18:40

    In addition to the other answers here, if you've forgotten to put:

    cmd.CommandType = CommandType.StoredProcedure;
    

    Then you will also get this error.

    0 讨论(0)
  • 2020-12-02 18:41

    I came across same issue. And my parameter was having null value. So I resolved by handling null value. If someone is not sure runtime value and want to handle null then simply use this. (And you don't want to change the SP/function.) E.g.

    sp.Value = Template ?? (object)DBNull.Value;
    
    0 讨论(0)
  • 2020-12-02 18:42

    If Template is not set (i.e. ==null), this error will be raised, too.

    More comments:

    If you know the parameter value by the time you add parameters, you can also use AddWithValue

    The EXEC is not required. You can reference the @template parameter in the SELECT directly.

    0 讨论(0)
  • 2020-12-02 18:45

    I had the same issue, to solve it just add exactly the same parameter name to your parameter collection as in your stored procedures.

    Example

    Let's say you create a stored procedure:

    create procedure up_select_employe_by_ID 
         (@ID int) 
    as
        select * 
        from employe_t 
        where employeID = @ID
    

    So be sure to name your parameter exactly as it is in your stored procedure this would be

    cmd.parameter.add("@ID", sqltype,size).value = @ID
    

    if you go

    cmd.parameter.add("@employeID", sqltype,size).value = @employeid 
    

    then the error happens.

    0 讨论(0)
提交回复
热议问题