how to read and write MP3s in the database

advertisements

how to read MP3 from Sql database. in sql i have stored the file as binary format. now i want to retrive the Mp3 file stored in the sql and show in my aspx page. how????

pls help...


In its simplest form this is how you would get the raw bytes, can't really show any more without knowing what you want it for...

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[];
      }
   }
}