无法识别sp_executesql参数

时间:2019-05-30 12:00:21

标签: sql-server-2012 ado.net

我有一个存储过程

CREATE PROCEDURE dbo.Employee_GetEmployeeByID
    @employeeID int 
AS
    select EM.EmployeeID,EM.FullName, GM.Gender,EM.PhoneNumber
    from EmployeesMaster EM
    JOIN GenderMaster GM ON EM.GenderID = GM.GenderID
    where (EM.EmployeeID = @employeeID )

我正在尝试执行(由ado.net代码生成)

exec sp_executesql N'Employee_GetEmployeeByID',N'@employeeID int',@employeeID=7

但是,我遇到了类似的错误

Msg 201, Level 16, State 4, Procedure Employee_GetEmployeeByID, Line 0
Procedure or function 'Employee_GetEmployeeByID' expects parameter '@employeeID', which was not supplied.

2 个答案:

答案 0 :(得分:0)

您是否先声明了变量?

DECLARE @employeeID int = 7 exec sp_executesql N'Employee_GetEmployeeByID',N'@employeeID int',@employeeID

答案 1 :(得分:0)

尝试此方法:

语法:

EXEC Procedure_Name Parameters

示例:

DECLARE @empid int = 5
EXEC Employee_GetEmployeeByID @empid