tags:

views:

170

answers:

2

Possible Duplicate:
how to read and write MP3 to database

Hi I need to read and store mp3 files as bytes in sql server and C#.. How can I do that?

A: 

Look into using FileStream, check out this article because it explains when, why, and how to use filestream.

In order for me to help you with C# please let me know how you plan on connecting and accessing your database.

Nix
A: 

SQL Server BLOB (Binary Large Object) lets you store image and mp3 data as raw binary in database. if you want get something up and running quickly, check this one.

http://www.databasejournal.com/features/mssql/article.php/3724556/Storing-Images-and-BLOB-files-in-SQL-Server-Part-2.htm

Using ADO, you can open a file stream to your mp3 and then add a named parameter (SQLParameter) of type SQLDbType.VarBinary to your SQLCommand object

SqlConnection conn = new SqlConnection(yourConnectionString);

SqlCommand cmd = null;
SqlParameter param = null;

cmd = new SqlCommand("INSERT INTO MP3 SET DATA = @BLOBPARAM WHERE
'some criteria'", conn);

FileStream fs = null;
fs = new FileStream("your mp3 file", FileMode.Open, FileAccess.Read);
Byte[] blob = new Byte[fs.Length];
fs.Read(blob, 0, blob.Length);
fs.Close();

param = new SqlParameter("@BLOBPARAM", SqlDbType.VarBinary, blob.Length,
ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, blob);
cmd.Parameters.Add(param);
conn.Open();
cmd.ExecuteNonQuery();
hi I tried ur code it works fine when I type the file name manually but I want to get it from the file upload control how can I do that?
Leema
the easiest way is to buffer mp3 file temporarily and then use the code above.