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

被折叠的 条评论
为什么被折叠?



