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(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)