[Solved] it is not saving without an image


If your image column allows for null values, change to

if(pb1 != null) 
{ 
    MemoryStream stream = new MemoryStream();
    pb1.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
    byte[] pic = stream.ToArray();
    command.Parameters.AddWithValue("@image", pic);
}
else 
{
    command.Parameters.AddWithValue("@image", System.Data.SqlTypes.SqlBinary.Null); 
    // edit: replaced incorreect DBNull.Value due to comment by Heinzi
}

System.Data.SqlTypes.SqlBinary.Null

Currently you are not providing enough parameters to your Sql if pb1 is null. When constructing the Sql it tries to access the SqlParameterCollection attached to your SqlCommand instance. Does not find anything for @image as given in the SqlCommand – hence the error.

10

solved it is not saving without an image