public void savePictureToSql(string kidCode) { SqlConnection con = new SqlConnection("data source = oriel; initial catalog = Kindergarten; user id = oriel; password = 123456;"); SqlCommand com = new SqlCommand("insert into Images values(@Pic) select @@IDENTITY update Persons set Picture =@@IDENTITY where Code=(select person_Code from kids where Code= " + kidCode + ")", con); MemoryStream stream = new MemoryStream(); pictureBox1.Image.Save(stream, System.Drawing.Imaging. ImageFormat.Jpeg); byte[] pic = stream.ToArray(); com.Parameters.AddWithValue("@Pic", pic); try { con.Open(); com.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { con.Close(); } } }