Advertisement
backlight0815

Untitled

Feb 10th, 2023
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data;
  8. using System.Data.Sql;
  9. using System.Data.SqlClient;
  10. using System.Configuration;
  11. using System.Drawing;
  12. using System.IO;
  13. using System.Web.Management;
  14.  
  15. namespace Learning
  16. {
  17. public partial class InsertMusicSheet_Backup_ : System.Web.UI.Page
  18. {
  19. protected void Page_Load(object sender, EventArgs e)
  20. {
  21.  
  22. }
  23.  
  24. private void InsertImage()
  25. {
  26.  
  27. string InstrumentType = string.Empty;
  28. if (rbPiano.Checked)
  29. {
  30. InstrumentType = "Piano";
  31. }
  32. else if (rbGuitar.Checked)
  33. {
  34. InstrumentType = "Guitar";
  35. }
  36. else if (rbDrum.Checked)
  37. {
  38. InstrumentType = "Drum";
  39. }
  40. else if (rbViolin.Checked)
  41. {
  42. InstrumentType = "Violin";
  43.  
  44. }
  45.  
  46. SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
  47.  
  48. if (flupBookPic.HasFile)
  49. {
  50. int imageLength = flupBookPic.PostedFile.ContentLength;
  51. byte[] imageArr = new byte[imageLength];
  52. HttpPostedFile image = flupBookPic.PostedFile;
  53. image.InputStream.Read(imageArr, 0, imageLength);
  54. SqlCommand cmd = new SqlCommand("Insert into MusicSheetTable(InstrumentType, Image) values (@InstrumentType, @Image)", con);
  55. con.Open();
  56. cmd.Parameters.AddWithValue("@InstrumentType", InstrumentType);
  57. cmd.Parameters.AddWithValue("@Image", SqlDbType.Image).Value = imageArr;
  58. lblError.Text = "Success";
  59. cmd.ExecuteNonQuery();
  60.  
  61.  
  62. }
  63. else
  64. {
  65. lblError.Text = "Rejected";
  66. }
  67. }
  68.  
  69. protected void btnUpdate_Click(object sender, EventArgs e)
  70. {
  71. try
  72. {
  73. InsertImage();
  74. }
  75. catch (Exception ex)
  76. {
  77. throw ex;
  78. }
  79.  
  80.  
  81. }
  82.  
  83.  
  84. }
  85. }
  86.  
  87.  
  88.  
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement