如何从sql server数据库将图像导入listview [英] How to get images into listview from sql server database

查看:75
本文介绍了如何从sql server数据库将图像导入listview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在我的网页上使用listview,我需要绑定来自sqlserver数据库的图像,因为我使用了图像处理程序(ashx)但是我无法获得图像。



任何人都可以帮助我吗?

Hi,

I am using listview in my webpage, there into i need to bind the images from sqlserver database,for that i used image handler(ashx) but i am unable to get images.

Can any one please help me?

推荐答案

在你的源代码你应该做类似下一个代码的事情:



YourDataEntity yourData = _db.YourDataEntities.FirstOrDefault(item => item.ID == ID);

byte [] imageBytes = yourData.Image; //从SQL访问Image字段!

MemoryStream stream = new MemoryStream(imageBytes);

//

HttpResponse response = HttpContext .Current.Response;

response.ContentType =image / jpeg;

byte [] buffer = new byte [4096];

while(true)

{

int read = stream.Read(buffer,0,buffer.Length);

if(read == 0)

休息;

//

response.OutputStream.Write(buffer,0,read);

}

//

response.End();
In your source code you should do something like the next code:

YourDataEntity yourData = _db.YourDataEntities.FirstOrDefault(item => item.ID == ID);
byte[] imageBytes = yourData.Image; //Access the "Image" field from SQL!
MemoryStream stream = new MemoryStream(imageBytes);
//
HttpResponse response = HttpContext.Current.Response;
response.ContentType = "image/jpeg";
byte[] buffer = new byte[4096];
while (true)
{
int read = stream.Read(buffer, 0, buffer.Length);
if (read == 0)
break;
//
response.OutputStream.Write(buffer, 0, read);
}
//
response.End();


这篇关于如何从sql server数据库将图像导入listview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆