【发布时间】:2010-08-19 10:36:20
【问题描述】:
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 文件。 当我执行此操作时,我找不到文件'',如何将上传的文件名从上传文件控件传递给文件流?
【问题讨论】: