【问题标题】:Entity Framework : When executing a command, parameters must be exclusively database parameters or values实体框架:执行命令时,参数必须是专有的数据库参数或值
【发布时间】:2016-09-05 07:41:45
【问题描述】:

这是什么:执行命令时,参数必须是数据库参数或值。

这是我的代码:

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

【问题讨论】:

    标签: c# sql-server entity-framework stored-procedures


    【解决方案1】:

    试试这样的:

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

    【讨论】:

      猜你喜欢
      • 2017-06-12
      • 1970-01-01
      • 2012-11-16
      • 2022-08-20
      • 1970-01-01
      • 1970-01-01
      • 2015-07-04
      • 2022-01-27
      • 1970-01-01
      相关资源
      最近更新 更多