if ( uploadFile.PostedFile.FileName.Trim() != String.Empty )
{
//----------- update图片
Stream imagedatastream;
SqlConnection myConn=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
imagedatastream = Request.Files["uploadFile"].InputStream ;
int imagedatalen = Request.Files["uploadFile"].ContentLength ;
string imagedatatype = Request.Files["uploadFile"].ContentType ; byte[] image = new byte[imagedatalen];
imagedatastream.Read(image,0,imagedatalen); String Psql="update Products set PPicture=@imgdata where PID=" + strPID; SqlCommand Pcommand=new SqlCommand(Psql,myConn); SqlParameter imgdata = new SqlParameter("@imgdata",SqlDbType.Image);
imgdata.Value=image;
Pcommand.Parameters.Add (imgdata); myConn.Open();
Pcommand.ExecuteReader();
myConn.Close();
//-----------
}
这是正确的二进制方式上传文件代码
但我现在不想用这方式了。想看到世界的名字和地址。该怎么改
不会不要回帖——————————
{
//----------- update图片
Stream imagedatastream;
SqlConnection myConn=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
imagedatastream = Request.Files["uploadFile"].InputStream ;
int imagedatalen = Request.Files["uploadFile"].ContentLength ;
string imagedatatype = Request.Files["uploadFile"].ContentType ; byte[] image = new byte[imagedatalen];
imagedatastream.Read(image,0,imagedatalen); String Psql="update Products set PPicture=@imgdata where PID=" + strPID; SqlCommand Pcommand=new SqlCommand(Psql,myConn); SqlParameter imgdata = new SqlParameter("@imgdata",SqlDbType.Image);
imgdata.Value=image;
Pcommand.Parameters.Add (imgdata); myConn.Open();
Pcommand.ExecuteReader();
myConn.Close();
//-----------
}
这是正确的二进制方式上传文件代码
但我现在不想用这方式了。想看到世界的名字和地址。该怎么改
不会不要回帖——————————
c://community.csdn.net/Expert/topic/5777/5777391.xml?
而二进制传上去的是<Binary>
直接读取内容写入数据库
http://dotnet.aspx.cc/article/78280914-a75c-40dc-9dac-322b3d81be35/read.aspx
从这里用Substring不就可以提取到实际的文件名吗?