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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
OopsUser
  • 4,642
  • 7
  • 46
  • 71

1 Answers1

5

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
  • 242,243
  • 40
  • 408
  • 536
  • 3
    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 Oct 24 '10 at 20:50