Skip to content

Instantly share code, notes, and snippets.

@riccardopirani
Last active October 25, 2017 09:55
Show Gist options
  • Save riccardopirani/f469316cda30e4d1665df1e36a487ac0 to your computer and use it in GitHub Desktop.
Save riccardopirani/f469316cda30e4d1665df1e36a487ac0 to your computer and use it in GitHub Desktop.
GDI+ error C#
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();
}
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