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?
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?
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.
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();