“SqlParameterCollection only accepts non-null SqlParameter type objects, not String objects”

后端 未结 8 2001
暗喜
暗喜 2021-01-04 07:23

I keep getting the exception

The SqlParameterCollection only accepts non-null SqlParameter type objects, not String objects

, while execut

8条回答
  •  半阙折子戏
    2021-01-04 07:50

    For any future readers of this question - the examples deal with .Add(), but .Remove() will also throw this error if not used correctly. The proper way to use .Add(), as has been documented by others is :

    cmd.Parameters.AddWithValue("Key", "Value");
    

    The proper way to use .Remove() is:

    cmd.Parameters.Remove(command.Parameters["Key"]); 
    

提交回复
热议问题