views:

13

answers:

1

I have a SQL Server database, and I want to store in image type column some string.

I'm trying to do the following :

SqlParameter myparam = new SqlParameter("@myparam", "VeryLongString");
myparam.SqlDbType = SqlDbType.Image;

when I add it to the command and then execute it, I get the following error :

Failed to convert parameter value from a String to a Byte[]

What seems to be the problem ?

thanks in advance

+3  A: 

An Image field in SQL Server stores a byte array (the bytes that make up the image), not a string.

If you're truly trying to pass in a very long string, you should use SqlDbType.Text.

Justin Niessner
Plus, the `IMAGE` datatype has been deprecated with SQL Server 2005 - if you need large text, use VARCHAR(MAX) - if you nee large binary storage, use VARBINARY(MAX).
marc_s