实体框架:当执行一个命令时,参数必须是唯一的数据库参数或值。

时间:2021-09-24 02:01:59

What is this: when executing a command, parameters must be exclusively database parameters or values.

这是什么:当执行一个命令时,参数必须是专有的数据库参数或值。

This is my code :

这是我的代码:

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);

and my stored procedure:

我的存储过程:

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

1 个解决方案

#1


-1  

Try something like this:

试试这样:

var command = new SqlCommand
{
    Connection = sqlConnection,
    CommandType = CommandType.StoredProcedure,
    CommandText = "MySpName"
};
command.Parameters.AddWithValue("@CityId", 1200);
//Add rest of your parameters here

#1


-1  

Try something like this:

试试这样:

var command = new SqlCommand
{
    Connection = sqlConnection,
    CommandType = CommandType.StoredProcedure,
    CommandText = "MySpName"
};
command.Parameters.AddWithValue("@CityId", 1200);
//Add rest of your parameters here