Skip to content

Instantly share code, notes, and snippets.

@riccardopirani
Created October 24, 2017 07:36
Show Gist options
  • Save riccardopirani/e5616903843957fb6feae45503b0ee8b to your computer and use it in GitHub Desktop.
Save riccardopirani/e5616903843957fb6feae45503b0ee8b to your computer and use it in GitHub Desktop.
Error must declare the scalar variable @immagine
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 Immagine=@Immagine 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("@Immagine", SqlDbType.VarBinary).Value = photo_aray;
}
command.Parameters.Add("@CodiceDistinta", SqlDbType.Int).Value = CodiceDistinta;
command.ExecuteNonQuery();
}
}
catch(Exception ex)
{
MessageBox.Show("Errore Aggiornamento Immagine: "+ex);
}
db.chiudiconnessione();
conn.Close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment