0

I Searched and searched and found no clear answer to this problem.

How to convert array byte to SQLBinary.

I've tried with Narrowing/Widening Operators but nothing seems to work...

Public Shared Widening Operator CType(ByVal p1 As Byte()) As SQLBinary

End Operator

This throws an error: Error 8 Either the parameter type or the return type of this conversion operator must be of the containing type 'reportManager'. reportManager.ascx.vb 12 37

So how do I go around this and create a function of the sorts that can convert this properly?

1 Answer 1

3

Just pass the Byte Array into the constructor:

    Dim objSqlBinary As New System.Data.SqlTypes.SqlBinary(myByteArray)

Widening CType Operators require that the class that you define them in be either the return type or what gets converted. I'm assuming you defined that operator in your reportManager.ascx.vb file, which is why its looking for reportManager.

Sign up to request clarification or add additional context in comments.

3 Comments

So with that I can keep operator where it is (yes it is in reportManager.ascx.vb) and just add that constructor?
No, don't use the operator and just do the code I posted in my answer to get an instance of a SqlBinary type from a byte array.
Thank you this works fine. Sadly this wasn't the solution to the bigger problem I hoped for :( Thanks a lot though. It helped.

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.