如何在sqlserver中插入音频文件。并在Windows播放器中播放它们。 [英] how to insert audio files in sqlserver. and play them in windows player.

查看:78
本文介绍了如何在sqlserver中插入音频文件。并在Windows播放器中播放它们。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是初学者..我正在制作在线媒体播放器。



如何在浏览和插入数据库时​​插入音频文件。请告诉我如何使用媒体播放器。



//存储过程

更改程序dbo.usp_addsong

@songid int = 1,

@artist varchar(50),

@songs_name varchar(50),

@album varchar( 50),

@song_file varbinary(MAX)



AS

开始

插入addongs(artist,song_name,album,song_file)值(@ artist,@ ssn_name,@ album,@ song_file);

结束





//





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


//


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();
   }





这是插入音频文件的代码..

但是我无法插入代码







和插入媒体播放器是以下程序好吗?





http://www.c-sharpcorner.com/UploadFile/8ea152/mp3-media-player-in-C-Sharp-4-0/ [ ^ ]

推荐答案

由于艺术家名称不是可选参数,我会在代码中删除if语句。看起来if语句永远不会是真的,因为文本框控件中的文本永远不会为空,可能是空白。



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.

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();
   }


这篇关于如何在sqlserver中插入音频文件。并在Windows播放器中播放它们。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆