sql server保存图片

本文详细介绍了如何使用SQL字段存储图片数据,包括将文件类型的input转换为byte[]数组,读取存储在数据库中的图片数据,并在网页上显示图片的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

sql field image

长度:自定义,1为一个字节,看你要上传多大的照片,长度就给多少。

file类型的input,转成byte[] 
 HttpPostedFile upFile = filePhoto.PostedFile;
int fileLength = upFile.ContentLength;
if (fileLength > 0)
{
Byte[] FileByteArray = new Byte[fileLength];
Stream StreamObject = upFile.InputStream;
StreamObject.Read(FileByteArray, 0, fileLength);
model.FPhoto = FileByteArray;
}

读取

View Code
SqlDataReader dr = xxxx.ExecuteReader(sql) as SqlDataReader;
if (dr.Read())
{
return (byte[])dr[0];

}

显示

View Code
context.Response.ContentType = "image/jpeg/gif/x-png";
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.BufferOutput = false;
int personnelId = WRequest.GetInt("id");
HR.Dao.Personnel.PersonnelDao bll = new Dao.Personnel.PersonnelDao();
byte[] file = (Byte[])bll.GetUserImage(personnelId); //把图片信息取出来
context.Response.BinaryWrite(file); 




转载于:https://www.cnblogs.com/zhoudemo/archive/2012/03/23/2412756.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值