Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Data;
- using System.Data.SqlClient;
- using System.IO;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace Learning
- {
- public partial class DrumSheet : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if(!Page.IsPostBack)
- {
- SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
- con.Open();
- SqlDataAdapter da = new SqlDataAdapter("Select * from Drum",con);
- DataTable dt = new DataTable();
- da.Fill(dt);
- Image1.ImageUrl = dt.Rows[0][1].ToString();
- }
- }
- protected void Save_Click(object sender, EventArgs e)
- {
- string folderPath = Server.MapPath("~/MusicSheetPictures/");
- if(!Directory.Exists(folderPath))
- {
- Directory.CreateDirectory(folderPath);
- }
- string fileName = img.Text;
- if (FileUpload1.HasFile)
- {
- // FileUpload1.SaveAs(Server.MapPath("MusicSheetPictures//" + FileUpload1.FileName));
- FileUpload1.SaveAs(folderPath + Path.GetFileName(FileUpload1.FileName));
- Image1.ImageUrl = "~/MusicSheetPictures/" + Path.GetFileName(FileUpload1.FileName);
- }
- else
- {
- if (Image1.ImageUrl == "")
- Image1.ImageUrl = img.Text;
- else
- FileUpload1.SaveAs(folderPath + Path.GetFileName(FileUpload1.FileName));
- Image1.ImageUrl = "~/MusicSheetPictures/" + Path.GetFileName(FileUpload1.FileName);
- }
- SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
- con.Open();
- string query1 = "insert into Drum (Photo,ImagePath) values(@photo,@ImagePath)";
- SqlCommand cmd1 = new SqlCommand(query1, con);
- cmd1.Parameters.AddWithValue("@photo", Image1.ImageUrl);
- cmd1.Parameters.AddWithValue("@ImagePath", "MusicSheetPictures/" + fileName);
- cmd1.ExecuteNonQuery();
- con.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement