Skip to content

Instantly share code, notes, and snippets.

@riccardopirani
Created November 27, 2017 07:26
Show Gist options
  • Save riccardopirani/908c37b58abd0917903156bed49178c3 to your computer and use it in GitHub Desktop.
Save riccardopirani/908c37b58abd0917903156bed49178c3 to your computer and use it in GitHub Desktop.
Gdi+ error
Image imm;
OpenFileDialog of = new OpenFileDialog();
of.Filter = "Image Files (*.bmp;*.jpg;*.jpeg,*.png)|*.BMP;*.JPG;*.JPEG;*.PNG";
if (of.ShowDialog() == DialogResult.OK)
{
pictureBoxImmagineDistinta.ImageLocation = of.FileName;
imm = pictureBoxImmagineDistinta.Image;
String PathImage = pictureBoxImmagineDistinta.ImageLocation;
String Query = "Update Distinta set Images=@Images where CodiceDistinta=@CodiceDistinta ";
SqlCommand command = new SqlCommand(Query, conn);
MemoryStream ms;
if (pictureBoxImmagineDistinta.Image != null)
{
//MessageBox.Show("Errore " + CodiceDistinta);
ms = new MemoryStream();
pictureBoxImmagineDistinta.Image.Save(ms, ImageFormat.Jpeg);
byte[] photo_aray = new byte[ms.Length];
ms.Position = 0;
ms.Read(photo_aray, 0, photo_aray.Length);
command.Parameters.AddWithValue("@Images", SqlDbType.Binary).Value = photo_aray;
command.Parameters.AddWithValue("@CodiceDistinta", SqlDbType.Int).Value = CodiceDistinta;
command.ExecuteNonQuery();
}
else
{
MessageBox.Show("Inserimento immagine non riuscito: ");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment