If IsNothing(command.Parameters("@UserId")) thrown an exception why?

command is a sqlcommand and i need to test the parameters collection before to add the @userid parameter so i use:

If IsNothing(command.Parameters("@UserId")) and i get this exception:

+ ex {"An SqlParameter with ParameterName'@UserId' is not contained by this SqlParameterCollection."} System.Exception

[408 byte] By [jnstaub] at [2007-12-21]
# 1
Avoid this exception by using SqlParameterCollection.Contains().
nobugz at 2007-9-10 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 2

nobugz solution will let you know if the parameter has been added to the collection and then you can test the "value" of the parameter to see if it contains a legitimate value...

DMan1 at 2007-9-10 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...