如何读写MP3到数据库

如何从Sql数据库中读取MP3。 在sql我已经将文件存储为二进制格式。 现在我想要检索存储在sql中的Mp3文件并在我的aspx页面中显示。 怎么样????

请帮忙……

在最简单的forms中,这就是你如何获得原始字节,如果不知道你想要什么就不能真正显示它…

private byte[] GetMp3Bytes(string connString) { SqlConnection conn = null; SqlCommand cmd = null; SqlDataReader reader = null; using (conn = new SqlConnection(connString)) { conn.Open(); using (cmd = new SqlCommand("SELECT TOP 1 Mp3_File FROM MP3_Table", conn)) using (reader = cmd.ExecuteReader()) { reader.Read(); return reader["Mp3_File"] as byte[]; } } } 

您可能希望使用Generic ASHX Handler来检索二进制数据,并使用正确的内容类型标题(“audio / mpeg”)将其传输到响应流。

如果您查看使用HttpHandlers在ASP.NET中显示图像的文章,那么您应该看到基本原理。 您只需要更改内容类型输出。