Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I would like to save image from picturebox after edit to database.
Now I save only picture without my drawings on picturebox.

C#
private void button2_Click(object sender, EventArgs e)
        {
            
            string sql = " UPDATE tabela_dzialki " +
            " SET wlasciciel_dzialki = " + "'" + textBox_wlasciciel_dzialki.Text + "'" + "," + " pow_dzialki = " + "'" + textBox_pow_dzialki.Text + "'" + "," +
            " adres_dzialki = " + "'" + textBox_adres_dzialki.Text + "'" + "," + " skala_dzialki = " + "'" + textBox_skala_dzialki.Text + "'" + "," +
            " oznwydz_dzialki = " + "'" + textBox_oznwydz_dzialki.Text + "'" + "," + " nrksiegi_dzialki = " + "'" + textBox_nrksiegi_dzialki.Text + "'" + "," +
            " typksiegi_dzialki = " + "'" + textBox_typksiegi_dzialki.Text + "'" + "," + " nrprowksiege_dzialki = " + "'" + textBox_nrprowksiege_dzialki.Text + "'" + "," +
            " datazap_dzialki = " + "'" + textBox_datazap_dzialki.Text + "'" +
            " WHERE nr_dzialki = " + "'" + textBox_nr_dzialki.Text + "'";
            System.Data.SqlServerCe.SqlCeConnection scon = new System.Data.SqlServerCe.SqlCeConnection("Data Source=C:\\Users\\Marcin\\Desktop\\BazaDanychMapKatastralnych\\WindowsFormsApplication1\\BazaDanychMapKatastralnych.sdf");
            System.Data.SqlServerCe.SqlCeCommand cmd = new System.Data.SqlServerCe.SqlCeCommand(sql, scon);

            //var bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            //pictureBox1.DrawToBitmap(bitmap, pictureBox1.ClientRectangle);
            Bitmap bmp = new Bitmap(pictureBox1.Image);
            //pictureBox1.Image = bmp;


            //Image myImage = pictureBox1.Image;

            System.IO.MemoryStream imgMemoryStream = new System.IO.MemoryStream();
            bmp.Save(imgMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] imgByteData = imgMemoryStream.GetBuffer();
            //Store image bytes data into database
            System.Data.SqlServerCe.SqlCeCommand cmd2 = new System.Data.SqlServerCe.SqlCeCommand(" UPDATE tabela_dzialki SET zdjecie_dzialki = @myPicture WHERE nr_dzialki = " + textBox_nr_dzialki.Text, scon);
            cmd2.Parameters.Add("@myPicture", SqlDbType.Image).Value = imgByteData;
            // Or cmd.Parameters.Add("@myPicture", SqlDbType.Binary).Value = imgByteData

            scon.Open();
            cmd.ExecuteReader();
            cmd2.ExecuteReader();
            scon.Close();
        }
Posted
Comments
lukeer 25-Jul-13 3:16am    
Draw something on the PictureBox. Minimize the program window. Restore it to previous size. Is your drawing still there?
stockCoders 25-Jul-13 3:25am    
Yes.
lukeer 25-Jul-13 5:01am    
Please use the "Improve question" link and provide the code you use to draw on the PictureBox.
Parviz Bazgosha 25-Jul-13 6:28am    
create grafics objects from your bitmap
after using draw methods
use flush mehtod of grafics
ather use save method of bitmap

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900