这是什么:执行命令时,参数必须是数据库参数或值。
这是我的代码:
var result = new SqlParameter
{
ParameterName = "@Duplicate",
SqlDbType = SqlDbType.Int,
Direction = ParameterDirection.Output,
Value = 0
};
_uow.ExecuteStoredProcedure("exec MySpName @ids='{0}',@CityId={1},@Search='{2}',@Duplicate Output", ids, 1200, "la",result);
和我的存储过程:
ALTER PROCEDURE [dbo].[MySpName]
@Ids nvarchar(max),
@CityId int,
@Search nvarchar(max),
@Duplicate INT OUTPUT
AS
BEGIN
SET NOCOUNT ON;
SET @Duplicate = (SELECT COUNT(Id)
FROM dbo.Companies
WHERE City IN (SELECT id
FROM [dbo].[SplitString](@Ids))
AND dbo.Companies.CityId = @CityId)
RETURN @Duplicate
END
答案 0 :(得分:-2)
尝试这样的事情:
var command = new SqlCommand
{
Connection = sqlConnection,
CommandType = CommandType.StoredProcedure,
CommandText = "MySpName"
};
command.Parameters.AddWithValue("@CityId", 1200);
//Add rest of your parameters here