Problems with writing an SQL Server varbinary(max) field using .Net1.1

M

Martin Horst

Hi,

I've got an application which is written in .Net 1.1. When I try to
write a varbinary(max) field using the SqlCommand and SqlParameter
classes I got an exception like this:

"The conversion of varchar into varbinary is invalid".

When I remove this field from my update statement, everything works
fine. The SQL paramter got the the DbNull value.
In the moment it is not possible for me to use another .Net framework,
because of the use of older external libraries. Has someone an idea what
I can do. In the moment I'm running out of time.

Thanks in advance
Martin
 
M

Martin Horst

Hi,

Marc said:
What is the DbType on the parameter?

good idea. That's the problem. The default is string and is not changed,
if the value is DbNull. My problem now is, that this methode, where I'm
creating and executing the SqlCmmand is generic. Is a value is null I
don't have a chance to determine the type of the value. Any ideas? I
tried setting object but this doesn't work ever. In .Net 2.0 or higher
you don't need to set the DbType if your value is DbNull.

Best regards
Martin
 
M

Marc Gravell

The best thing I can suggest is to write an overload of your "AddParam"
(or whatever) that accepts a byte[], and ensure that it is passed as a
byte[] (not an object) so that the overload gets used. Then in that
overload, at least know know what you are dealing with and can set the
parameter appropriately... not ideal, however...
 
I

Ignacio Machin ( .NET/ C# MVP )

Hi,

I've got an application which is written in .Net 1.1. When I try to
write a varbinary(max) field using the SqlCommand and SqlParameter
classes I got an exception like this:

"The conversion of varchar into varbinary is invalid".

When I remove this field from my update statement, everything works
fine. The SQL paramter got the the DbNull value.
In the moment it is not possible for me to use another .Net framework,
because of the use of older external libraries. Has someone an idea what
I can do. In the moment I'm running out of time.

Thanks in advance
Martin

Hi,

IIRC varbinary expect a byte[] , so you can convert your string to
byte[]
 

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