Advertisement
backlight0815

DrumSheet

Feb 12th, 2023
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Web;
  9. using System.Web.UI;
  10. using System.Web.UI.WebControls;
  11.  
  12. namespace Learning
  13. {
  14. public partial class DrumSheet : System.Web.UI.Page
  15. {
  16. protected void Page_Load(object sender, EventArgs e)
  17. {
  18.  
  19. if(!Page.IsPostBack)
  20. {
  21. SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
  22. con.Open();
  23.  
  24. SqlDataAdapter da = new SqlDataAdapter("Select * from Drum",con);
  25. DataTable dt = new DataTable();
  26. da.Fill(dt);
  27. Image1.ImageUrl = dt.Rows[0][1].ToString();
  28. }
  29. }
  30.  
  31. protected void Save_Click(object sender, EventArgs e)
  32. {
  33. string folderPath = Server.MapPath("~/MusicSheetPictures/");
  34. if(!Directory.Exists(folderPath))
  35. {
  36. Directory.CreateDirectory(folderPath);
  37. }
  38. string fileName = img.Text;
  39.  
  40. if (FileUpload1.HasFile)
  41. {
  42. // FileUpload1.SaveAs(Server.MapPath("MusicSheetPictures//" + FileUpload1.FileName));
  43. FileUpload1.SaveAs(folderPath + Path.GetFileName(FileUpload1.FileName));
  44. Image1.ImageUrl = "~/MusicSheetPictures/" + Path.GetFileName(FileUpload1.FileName);
  45.  
  46.  
  47. }
  48. else
  49. {
  50. if (Image1.ImageUrl == "")
  51. Image1.ImageUrl = img.Text;
  52. else
  53. FileUpload1.SaveAs(folderPath + Path.GetFileName(FileUpload1.FileName));
  54. Image1.ImageUrl = "~/MusicSheetPictures/" + Path.GetFileName(FileUpload1.FileName);
  55. }
  56. SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
  57. con.Open();
  58. string query1 = "insert into Drum (Photo,ImagePath) values(@photo,@ImagePath)";
  59. SqlCommand cmd1 = new SqlCommand(query1, con);
  60.  
  61. cmd1.Parameters.AddWithValue("@photo", Image1.ImageUrl);
  62. cmd1.Parameters.AddWithValue("@ImagePath", "MusicSheetPictures/" + fileName);
  63.  
  64.  
  65.  
  66. cmd1.ExecuteNonQuery();
  67. con.Close();
  68.  
  69.  
  70.  
  71.  
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement