Created
November 27, 2017 07:26
-
-
Save riccardopirani/908c37b58abd0917903156bed49178c3 to your computer and use it in GitHub Desktop.
Gdi+ error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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