![]() |
#2
shezhenhui19892008-04-16 11:54
private void UploadFile()
{ string strFilePathName = loFile.PostedFile.FileName; string strFileName = Path.GetFileName(strFilePathName); int FileLength = loFile.PostedFile.ContentLength; if(FileLength<=0) return; try { Byte[] FileByteArray = new Byte[FileLength]; Stream StreamObject = loFile.PostedFile.InputStream; StreamObject.Read(FileByteArray,0,FileLength); string strCon = System.Configuration.ConfigurationSettings.AppSettings["DSN"]; SqlConnection Con = new SqlConnection(strCon); String SqlCmd = "INSERT INTO ImageStore (ImageData, ImageContentType, ImageDescription, ImageSize) VALUES (@Image, @ContentType, @ImageDescription, @ImageSize)"; SqlCommand CmdObj = new SqlCommand(SqlCmd, Con); CmdObj.Parameters.Add("@Image",SqlDbType.Binary, FileLength).Value = FileByteArray; CmdObj.Parameters.Add("@ContentType", SqlDbType.VarChar,50).Value = loFile.PostedFile.ContentType; CmdObj.Parameters.Add("@ImageDescription", SqlDbType.VarChar,200).Value = tbDescription.Text; CmdObj.Parameters.Add("@ImageSize", SqlDbType.BigInt,8).Value = FileLength; Con.Open(); CmdObj.ExecuteNonQuery(); Con.Close(); Response.Redirect("ShowAll.aspx"); } catch(Exception ex) { throw ex; } } |
怎么实现上传图片到数据库呢?
要用FileUpLoad控件吗?
我在网上查的,好象首先要设置enctype, enctype是什么?在哪里?
请教了.