Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- using System.Data.Sql;
- using System.Data.SqlClient;
- using System.Configuration;
- using System.Drawing;
- using System.IO;
- using System.Web.Management;
- namespace Learning
- {
- public partial class InsertMusicSheet_Backup_ : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- private void InsertImage()
- {
- string InstrumentType = string.Empty;
- if (rbPiano.Checked)
- {
- InstrumentType = "Piano";
- }
- else if (rbGuitar.Checked)
- {
- InstrumentType = "Guitar";
- }
- else if (rbDrum.Checked)
- {
- InstrumentType = "Drum";
- }
- else if (rbViolin.Checked)
- {
- InstrumentType = "Violin";
- }
- SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
- if (flupBookPic.HasFile)
- {
- int imageLength = flupBookPic.PostedFile.ContentLength;
- byte[] imageArr = new byte[imageLength];
- HttpPostedFile image = flupBookPic.PostedFile;
- image.InputStream.Read(imageArr, 0, imageLength);
- SqlCommand cmd = new SqlCommand("Insert into MusicSheetTable(InstrumentType, Image) values (@InstrumentType, @Image)", con);
- con.Open();
- cmd.Parameters.AddWithValue("@InstrumentType", InstrumentType);
- cmd.Parameters.AddWithValue("@Image", SqlDbType.Image).Value = imageArr;
- lblError.Text = "Success";
- cmd.ExecuteNonQuery();
- }
- else
- {
- lblError.Text = "Rejected";
- }
- }
- protected void btnUpdate_Click(object sender, EventArgs e)
- {
- try
- {
- InsertImage();
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement