I\'m getting the error when accessing a Stored Procedure in SQL Server
Server Error in \'/\' Application.
Procedure or function \'ColumnSeek\' expects parame
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.
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
.
In addition to the other answers here, if you've forgotten to put:
cmd.CommandType = CommandType.StoredProcedure;
Then you will also get this error.
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;
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.
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.