Insert picture working fine, I have problem with update...some help?
- string fileName;
- private void buttonupload_Click(object sender, EventArgs e)
- {
- //Read image file
- using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "JPEG|*.jpg|BMP|*.bmp|PNG|*.png|All Files|*.*", ValidateNames = true, Multiselect = false })
- {
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- fileName = ofd.FileName;
- pictureBox1.Image = System.Drawing.Image.FromFile(fileName);
- }
- }
- }
- private void buttonsave_Click(object sender, EventArgs e)
- {
- byte[] img_arr = null;
- MemoryStream ms = new MemoryStream();
- pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
- img_arr = ms.GetBuffer();
- using (SqlConnection openCon = new SqlConnection(cs))
- {
- string saveStaff = "INSERT INTO dbo.radnici ( data) VALUES (@data)";
- using (SqlCommand querySaveStaff = new SqlCommand(saveStaff))
- {
- querySaveStaff.Connection = openCon;
- querySaveStaff.Parameters.AddWithValue("@data", img_arr);
- openCon.Open();
- querySaveStaff.ExecuteNonQuery();
- openCon.Close();
- }
- }
- else
- {
- using (SqlConnection openCon = new SqlConnection(cs))
- {
- string updateStaff = "UPDATE dbo.radnici SET data=@data WHERE id= " + idTextBox.Text;
- using (SqlCommand querySaveStaff = new SqlCommand(saveStaff))
- {
- queryupdateStaff.Connection = openCon;
- queryupdateStaff.Parameters.AddWithValue("@data", img_arr);
- openCon.Open();
- queryupdateStaff.ExecuteNonQuery();
- MessageBox.Show("Uspješno ste izmenili stavku!", "Informacija", MessageBoxButtons.OK, MessageBoxIcon.Information);
- openCon.Close();
- }
- }
- }
Goran BibicPosted May 27, 2018, 1:04 PM