Save audio into SQL
Hello everybody, I want to save a file audio into SQL but I don't know how to save. Can you help me, please?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Dinkar ChavhanPosted Apr 22, 2011, 8:07 AM
Audio Song Uploading and save in DB
In this Article we see how to upload Audio or MP3 song in Database and also Aplication folder like Audio.This is simple code useful for Developer
So lets see step by step procedure
Step 1) Take textbox and fileupload control and Button
Step 2)Create table like
{
Create table with two colomns like id(pk) and song (
}
Step 3)Now write stored procedure
{
ALTER procedure Sp_Audio(@id int,@song varchar(50))
As
Begin
insert into Audio(id,song)values(@id,@song)
end
}
}
Step 4)Now double click on Button and write code
{
SqlConnection cn = new SqlConnection("Give Path");
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cn.Open();
cmd.CommandText = "Sp_Audio";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", TextBox1.Text);
cmd.Parameters.AddWithValue("@song", FileUpload1.FileName);
int i=cmd.ExecuteNonQuery();
if (FileUpload1.HasFile)
{
string fname = FileUpload1.FileName.ToString();
string folderpath = "~/Audio";
string path = HttpContext.Current.Server.MapPath(folderpath);
FileUpload1.PostedFile.SaveAs(path + "\\" + fname);
Label1.Text = "file uploaded successfully";
}
}
}
Step 5)Now Run Application
Krishna GaradPosted Mar 30, 2011, 12:28 AM