471,853 Members | 1,484 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,853 software developers and data experts.

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 4586
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

NeoPa
reply views Thread by NeoPa | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.