SqlConnection conn = new SqlConnection(「Data Source = DDPRO8-WIN7X86 \ SQLEXPRESS; Initial Catalog = mp3bytes; Persist Security Info = True; Integrated security = true; User ID =; Password = ;「); SqlCommand cmd = null; SqlParameter param = null; cmd = new SqlCommand(「INSERT INTO mp3_bytes(songs)」+「Values(@songs)」,conn); FileStream fs = null;將文件上傳控制文件名傳遞到文件流
string path = fileUpload.FileName;
fs = new FileStream(path, FileMode.Open, FileAccess.Read);
Byte[] song = new Byte[fs.Length];
fs.Read(song, 0, song.Length);
fs.Close();
param = new SqlParameter("@songs", SqlDbType.VarBinary, song.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, song);
cmd.Parameters.Add(param);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
其中的FileUpload是文件上傳控制..我上傳MP3文件.. 當我執行此我越來越找不到文件「」我怎麼可以通過上傳的文件名從上傳到FILESTREAM文件控制..
謝謝你..
我想,太.. – Leema 2010-08-19 10:45:06
但我需要一個mp3文件的byte []數組存儲到數據庫在這種情況下我該怎麼辦呢? – Leema 2010-08-19 11:03:58
嗨thaaaaaanks現在它的工作... – Leema 2010-08-19 11:31:30