Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i am a beginner.. n i m making online media player.

how to insert audio file when browsing and insert into database. And please do tell me how to use media player.

//stored procedure
ALTER PROCEDURE dbo.usp_addsong
@songid int = 1,
@artist varchar(50),
@song_name varchar(50),
@album varchar(50),
@song_file varbinary(MAX)

AS
begin
insert into addsongs (artist, song_name, album, song_file) values (@artist , @song_name, @album, @song_file);
End


//


C#
protected void btnaddsong_Click(object sender, EventArgs e)
   {
       con.Open();
       {
           cmd.CommandText = "usp_addsong";
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@artist", txtartist.Text);
           cmd.Parameters.AddWithValue("@song_name", txtsongname.Text);
           cmd.Parameters.AddWithValue("@album", txtalbum.Text);
           if (txtalbum.Text != null && txtalbum.Text != null)
           {
               cmd.CommandText = "usp_artist";
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@artist_name", txtartist.Text);
           }
           cmd.Parameters.AddWithValue("@song_file", songupload.FileBytes);
           cmd.Connection = con;
           cmd.ExecuteNonQuery();
           int check = 0;
           check = cmd.ExecuteNonQuery();
           if (check == 1)
           {
               con.Close();
           }
           else
           {
               Response.Write("Error");
           }
       }
       con.Close();
   }


this is code to insert audio file..
but i cannot insert code



and inserting media player is the below procedure ok??


http://www.c-sharpcorner.com/UploadFile/8ea152/mp3-media-player-in-C-Sharp-4-0/[^]
Posted
Comments
AndrewCharlz 14-Oct-14 0:20am    
Never make ur Db huge save the path in the db, Save it in a physical location and save its path in db.
Prasad Avunoori 14-Oct-14 1:16am    
Yes, Better you save the path itself.
Member 11383656 5-Feb-15 12:29pm    
can i get vb ,net coding for this

1 solution

Since the artist name is not an optional parameter I would loose the if statement in your code. It looks like that if statement will never be true anyway because the text in a textbox control will never be null, possibly blank.

C#
protected void btnaddsong_Click(object sender, EventArgs e)
   {
       con.Open();
       {
           cmd.CommandText = "usp_addsong";
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@artist", txtartist.Text);
           cmd.Parameters.AddWithValue("@song_name", txtsongname.Text);
           cmd.Parameters.AddWithValue("@album", txtalbum.Text);
           cmd.Parameters.AddWithValue("@artist_name", txtartist.Text);
           cmd.Parameters.AddWithValue("@song_file", songupload.FileBytes);
           cmd.Connection = con;
           cmd.ExecuteNonQuery();
           int check = 0;
           check = cmd.ExecuteNonQuery();
           if (check == 1)
           {
               con.Close();
           }
           else
           {
               Response.Write("Error");
           }
       }
       con.Close();
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900