1

I have the following code

cmd. Parameters. AddWithValue("@Password",
    (string.IsNullOrEmpty(member.Password))
        ? (object)DBNull.Value
        : member.Password);
cmd.Parameters.AddWithValue("@Image",
    (member.Image==null)
        ? (object)SqlDbType.Image
        : member.Image);

unable to add null value to image column.

I get this error:

Operand type clash: int is incompatible with image

5
  • Have you tried simply ("@Image", member.Image) ? Commented Feb 17, 2014 at 12:16
  • Or using DBNull.Value also for the image parameter? Commented Feb 17, 2014 at 12:19
  • yes I have tried but it ask @image parameter value is not supplied Commented Feb 17, 2014 at 12:19
  • image type is actually byte[] . Conversion is not possible Commented Feb 17, 2014 at 12:24
  • cmd.Parameters.AddWithValue("@Image", (member.Image==null) ? (object)DBNull.Value : member.Image); Commented Feb 17, 2014 at 12:29

2 Answers 2

7

Here you go: you're passing SqlDbType.Image (more commonly known as 7) when you should be passing a null:

cmd.Parameters.AddWithValue("@Image",
(member.Image==null)
    ? (object)DBNull.Value
    : member.Image);

If you want to specify the data type explicitly, do that separately; for example:

cmd.Parameters.AddWithValue("@Image",
(member.Image==null)
    ? (object)DBNull.Value
    : member.Image).SqlDbType = SqlDbType.Image;
Sign up to request clarification or add additional context in comments.

Comments

0

this is only solution your problem

int filLength = 0;
byte[] byteImageArray;
byteImageArray = new byte[Convert.ToInt32(filLength)];
cmd.Parameters.AddWithValue("@Image",
    (member.Image==null)
        ? byteImageArray
        : member.Image);

1 Comment

Hello and welcome to Stack Overflow! Would you please elaborate and comment a little bit more on why this solution works?

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.