Guest User

Untitled

a guest
Oct 15th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3.  
  4. OpenFileDialog getImage = new OpenFileDialog();
  5. getImage.InitialDirectory = "C:\";
  6. getImage.Filter = "Archivos de Imagen (*.jpg)(*.jpeg)|*.jpg;*.jpeg|PNG(*.png)|*.png";
  7. if (getImage.ShowDialog() == DialogResult.OK)
  8. {
  9. pictureBox1.ImageLocation = getImage.FileName;
  10. pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
  11. }
  12. else
  13. {
  14. }
  15. }
  16.  
  17. private void button2_Click(object sender, EventArgs e)
  18. {
  19. if (textBox1.Text != "" || comboBox1.Text != "" || comboBox2.Text != "")
  20. {
  21.  
  22. SqlCommand agregar = new SqlCommand("Insert Into Equipos values ((RTRIM(LTRIM(" + textBox1.Text + "))), (RTRIM(LTRIM('" + variable + "'))), (RTRIM(LTRIM('" + textBox3.Text + "'))) ,(RTRIM(LTRIM('" + textBox2.Text + "'))), (RTRIM(LTRIM('" + comboBox1.Text + "'))), (RTRIM(LTRIM('" + comboBox2.Text + "'))), (RTRIM(LTRIM('" + textBox10.Text + "'))), @Imagen)", cadena);
  23. try
  24. {
  25. cadena.Open();
  26.  
  27. agregar.ExecuteNonQuery();
  28. MessageBox.Show("Agregado");
  29.  
  30. Variables.equipos1 = textBox1.Text;
  31. Variables.equipos2 = variable;
  32. Variables.equipos3 = textBox2.Text;
  33. Variables.equipos4 = comboBox1.Text;
  34. Variables.equipos5 = comboBox2.Text;
  35. Variables.equipos6 = textBox10.Text;
  36. Variables.dialogo = true;
  37. }
  38. catch (Exception ex)
  39. {
  40. MessageBox.Show("Error" + ex);
  41. }
  42. finally
  43. {
  44. cadena.Close();
  45. textBox1.Clear();
  46. textBox2.Clear();
  47. }
  48.  
  49. }
  50. else
  51. {
  52. cadena.Close();
  53. MessageBox.Show("No puede dejar vacio");
  54.  
  55. textBox2.Clear();
  56. }
  57. }
  58.  
  59. public byte[] ImageToByteArray(System.Drawing.Image imagen)
  60. {
  61. MemoryStream ms = new MemoryStream();
  62. imagen.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  63. return ms.ToArray();
  64. }
  65.  
  66. byte[] byteArrayImagen = ImageToByteArray(PictureBox1.Image)
  67. SqlCommand command = new SqlCommand();
  68. command.Text="INSERT INTO TABLA (CAMPO) values (@imagen)";
  69. command.Parameters.AddWithValue("@imagen",byteArrayImagen);
  70. command.ExecuteNonQuery();
Add Comment
Please, Sign In to add comment