将图片直接传到数据库的方法
2006-07-18 11:07
260 查看
(将图片转换为byte类型,然后用流的方式传输,并且将imagetype也同时上载到数据库的相应字段中。)
(浏览图片的方法,设置一个图片控件,将该图片控件的imageurl设置为
"../system/image.aspx?id="+dr1["carid"].ToString(),传递图片的识别id,然后在image.aspx中的
formload中处理图片显示,用到
Response.ContentType=dr["imagetype"].ToString();Response.BinaryWrite((byte[])dr["carimage"]);)
stream imgstream;
imgstream=uploadfile1.postedfile.inputstream;
int len=uploadfile1.postedfile.contentlength;
byte[] imagedata=new byte[len];
string imguploadname=uploadfile1.postedfile.filename;
string imgcontenttype=uploadfile1.postedfile.contenttype;
string imagename=getlastindexof("\\",imguploadname);
int n=imgstream.read(imagedata,0,len)
mycommand.parameters["image"].value=imagedata
mycommand.parameters["imagetype"].value=imgcontenttype;
public string getlastindexof(string lookfor,string mystring)
{
int strpos;
strpos=mystring.lastindexof(lookfor);
return mystring.substring(strpos+1);
}
(浏览图片的方法,设置一个图片控件,将该图片控件的imageurl设置为
"../system/image.aspx?id="+dr1["carid"].ToString(),传递图片的识别id,然后在image.aspx中的
formload中处理图片显示,用到
Response.ContentType=dr["imagetype"].ToString();Response.BinaryWrite((byte[])dr["carimage"]);)
stream imgstream;
imgstream=uploadfile1.postedfile.inputstream;
int len=uploadfile1.postedfile.contentlength;
byte[] imagedata=new byte[len];
string imguploadname=uploadfile1.postedfile.filename;
string imgcontenttype=uploadfile1.postedfile.contenttype;
string imagename=getlastindexof("\\",imguploadname);
int n=imgstream.read(imagedata,0,len)
mycommand.parameters["image"].value=imagedata
mycommand.parameters["imagetype"].value=imgcontenttype;
public string getlastindexof(string lookfor,string mystring)
{
int strpos;
strpos=mystring.lastindexof(lookfor);
return mystring.substring(strpos+1);
}
相关文章推荐
- CKEditor中上传图片传到数据库的一个比较取巧的方法
- 用C#编程从数据库中读取图片数据导进Excel文件的方法(如何从数据库中读取保存的文件,直接打开,中间不保存到本地)
- php抓取新闻方法实例(包含新闻图片),配好数据库和表结构可直接使用
- 用C#编程从数据库中读取图片数据导进Excel文件的方法(如何从数据库中读取保存的文件,直接打开,中间不保存到本地)
- jsp图片上传到数据库里面之后,不能直接在页面上显示,而是提示下载
- jtopo 实现调用saveImageInfo()方法直接下载图片,支持所有浏览器
- 服务器直接关机,再开机,硬重启时把数据库搞坏了,状态为“可疑”的解决方法
- PowerBuilder直接导出数据库连接文件INI的方法
- MySql直接备份数据库文件的方法(MyISAM和InnoDB有所不同)
- SQL2000下将数据库直接备份到网络上其他计算机硬盘的方法
- 待整理。。。blob。。。从页面存图片到数据库或本地的方法
- 上传自定义水印图片到图片空间及保存数据库的方法
- 让magento操作支持直接操作数据库方法
- Django中实现点击图片链接强制直接下载的方法
- Django中实现点击图片链接强制直接下载的方法
- 从数据库提取图片文件显示到前端页面的一种方法
- Java将对象直接在数据库中存取的方法
- mysql 直接从date 文件夹备份表,还原数据库之后提示 table doesn`t exist的原因和解决方法
- C#保存图片到数据库并读取显示图片的方法
- Android TextView里直接显示图片的三种方法