Last active
October 25, 2017 09:55
-
-
Save riccardopirani/f469316cda30e4d1665df1e36a487ac0 to your computer and use it in GitHub Desktop.
GDI+ error C#
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
private void pictureBoxImmagineDistinta_DoubleClick(object sender, EventArgs e) | |
{ | |
SqlConnection conn = db.apriconnessione(); | |
try | |
{ | |
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 Query = "Update Distinta set Images=@Images where CodiceDistinta=@CodiceDistinta "; | |
SqlCommand command = new SqlCommand(Query, conn); | |
MemoryStream ms; | |
if (pictureBoxImmagineDistinta.Image != null) | |
{ | |
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.Add("@Images", SqlDbType.Binary).Value = photo_aray; | |
command.Parameters.Add("@CodiceDistinta", SqlDbType.Int).Value = CodiceDistinta; | |
command.ExecuteNonQuery(); | |
} | |
else | |
{ | |
MessageBox.Show("Inserimento immagine non riuscito"); | |
} | |
} | |
} | |
catch(Exception ex) | |
{ | |
MessageBox.Show("Errore Aggiornamento Immagine: "+ex); | |
} | |
db.chiudiconnessione(); | |
conn.Close(); | |
} |
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
CREATE TABLE [dbo].[Distinta]( | |
[CodiceDistinta] [int] IDENTITY(1,1) NOT NULL, | |
[IdDistinta] [varchar](500) NULL, | |
[DataInserimento] [datetime] NULL, | |
[DataModifica] [datetime] NULL, | |
[Descrizione] [varchar](500) NULL, | |
[DescrizioneEstesa] [varchar](6000) NULL, | |
[UnitaMisura] [varchar](10) NULL, | |
[Images] [varbinary](max) NULL, | |
PRIMARY KEY CLUSTERED | |
( | |
[CodiceDistinta] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] | |
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment