0
cmd.Parameters.Add(New SqlParameter("LossID", SqlDbType.Int).Direction = ParameterDirection.Output)
.....
Dim LossID as integer

lossID = cmd.Parameters("@LossID").Value

When I add my output parameter to my command object, I am receiving a

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

How do I correctly place my return value into the lossID integer? thank you very much

1
  • Your definition uses LossID and when you try to access your parameters collection, you use @LossID - I think you should consistently use the notation with the leading at (@) sign. Commented Apr 28, 2011 at 15:56

1 Answer 1

2

You need to separate the assignment of the Direction property from the adding of the parameter to the parameters collection.

param = New SqlParameter("LossID", SqlDbType.Int)
param.Direction = ParameterDirection.Output
cmd.Parameters.Add(param)
Sign up to request clarification or add additional context in comments.

2 Comments

Seems wierd, why cant i one line it?
Because the type of New SqlParameter("LossID", SqlDbType.Int).Direction = ParameterDirection.Output is a Boolean, not a SqlParameter while cmd.Parameters.Add(.) needs to be given an object of type SqlParameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.