主要方法如下://图片能插入成功,但就是类型不对.
HttpPostedFile HPF=File1.PostedFile; //将文件域F上传的文件赋给HPF--------
int FL=HPF.ContentLength;
if(FL != 0)
{
string FT=HPF.ContentType;
Byte[] FBA=new Byte[FL];//声明一个字节数组FBA,用于存放文件的数据流
Stream SO;//声明流对象SO
SO=HPF.InputStream;//将上传文件的输入流赋予SO
SO.Read(FBA,0,FL);//流对象SO执行Read方法将输入流读入字节数组FBA
string strsql1 = "Insert into Productsinfo (ID,Photo,FileLength,ContentType) Values ('8',@fs,'"+FL+"','"+FT+"')";
//调用类dbhelp中方法ExecuteSqlInsertImg将图片插入到数据库,返回受影响的行数.
this.Label2.Text = dbhelp.ExecuteSqlInsertImg(strsql1,FBA).ToString();
}例如:
插入一张GIF图片到数据库后,FileLength显示的内容是application/octet-stream,而不是image/gif记录为: ID Photo FileLength ContentType
1 <Binary> application/octet-stream 86302 我要是这种结果: ID Photo FileLength ContentType
1 <Binary> image/gif 86302
HttpPostedFile HPF=File1.PostedFile; //将文件域F上传的文件赋给HPF--------
int FL=HPF.ContentLength;
if(FL != 0)
{
string FT=HPF.ContentType;
Byte[] FBA=new Byte[FL];//声明一个字节数组FBA,用于存放文件的数据流
Stream SO;//声明流对象SO
SO=HPF.InputStream;//将上传文件的输入流赋予SO
SO.Read(FBA,0,FL);//流对象SO执行Read方法将输入流读入字节数组FBA
string strsql1 = "Insert into Productsinfo (ID,Photo,FileLength,ContentType) Values ('8',@fs,'"+FL+"','"+FT+"')";
//调用类dbhelp中方法ExecuteSqlInsertImg将图片插入到数据库,返回受影响的行数.
this.Label2.Text = dbhelp.ExecuteSqlInsertImg(strsql1,FBA).ToString();
}例如:
插入一张GIF图片到数据库后,FileLength显示的内容是application/octet-stream,而不是image/gif记录为: ID Photo FileLength ContentType
1 <Binary> application/octet-stream 86302 我要是这种结果: ID Photo FileLength ContentType
1 <Binary> image/gif 86302
解决方案 »
- 安装了SqlServer2005就不能创建aspNetDb.mdf了??!!
- BLL就是每个表都写个增删查改类么?
- ASP.NET如果隐藏下载真实文件名?就是不显示http://host/file.exe。
- 3个面试问题,没回答出来.
- datagrid没有直接查看记录数的吗?都是用dataset.tables.rows.count方法吗?
- 如何确定是否在 .NET Framework 中安装了 Service Pack
- datagrid的显示格式一问
- 奇怪的问题,气得我吐血!--参数为奇数个字符就出错,偶数个字符就不出错!
- 请叫各位大虾,在.aspx中如何调用javascript,不胜感激!
- 高手请进!!
- 关于自定义数据表的问题
- Instance的问题? 速度结贴,高手进!
不能这样吧,用SqlCommand这样相当于把FL变成FL.ToStringg()使用了