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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.