Object operand error message

T

tshad

In VS 2008, why can I not do:

trace.warn("parameters(3) = " & parameters(3).value)

I get an error:

Option Strict on prohibits operands of type Object for operator '&'

This worked fine in 2003.

parameters is defined as:

Dim parameters As SqlParameter() = { _
New SqlParameter("@ScreenQuestionID", SqldbType.Int), _
....

Thanks,

Tom
 
G

Göran Andersson

tshad said:
In VS 2008, why can I not do:

trace.warn("parameters(3) = " & parameters(3).value)

I get an error:

Option Strict on prohibits operands of type Object for operator '&'

This worked fine in 2003.

parameters is defined as:

Dim parameters As SqlParameter() = { _
New SqlParameter("@ScreenQuestionID", SqldbType.Int), _
...

Thanks,

Tom

Because the Value property of the SqlParameter class is of the type Object.

You can cast the object to the actual type that you have stored in the
parameter, the & operator will then use the ToString method to format it
into a string:

trace.warn("parameters(3) = " & DirectCast(parameters(3).Value, Integer))

Or you can simply use the ToString method on the object to get the
string representation:

trace.warn("parameters(3) = " & parameters(3).Value.ToString())
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top