SqlConnection connection = new SqlConnection("connection string here");
SqlCommand command = new SqlCommand("UPDATE MyTable SET Picture = @Picture WHERE ID = 1", connection);
// Create an Image object.
using (Image picture = Image.FromFile("file path here"))
{
// Create an empty stream in memory.
using (MemoryStream stream = new MemoryStream())
{
// Fill the stream with the binary data from the Image.
picture.Save(stream, ImageFormat.Jpeg);
// Get an array of Bytes from the stream and assign to the parameter.
command.Parameters.Add("@Picture", SqlDbType.VarBinary).Value = stream.GetBuffer();
}
}
connection.Open();
command.ExecuteNonQuery();
connection.Close();