469,282 Members | 1,940 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

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

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
Jun 27 '08 #1
4 4498
What is the DbType on the parameter?
Jun 27 '08 #2
Hi,

Marc Gravell schrieb:
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
Jun 27 '08 #3
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...
Jun 27 '08 #4
On Apr 22, 9:33*am, Martin Horst <pub1-R...@martinhorst.dewrote:
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[]
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.