Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql-从数据库读取图像_Sql_Image_Httphandler - Fatal编程技术网

Sql-从数据库读取图像

Sql-从数据库读取图像,sql,image,httphandler,Sql,Image,Httphandler,在从数据库读取图像时,我不断得到错误图像图标 以下是HttpHandler代码: public void ProcessRequest(HttpContext context) { .... //After we got the data table: byte[] image = (byte[])dt.Rows[0]["Picture"]; context.Response.ContentType = dt.Rows[0]["PictureType"].ToSt

在从数据库读取图像时,我不断得到错误图像图标

以下是HttpHandler代码:

public void ProcessRequest(HttpContext context) {
    ....
    //After we got the data table:
    byte[] image = (byte[])dt.Rows[0]["Picture"];
    context.Response.ContentType = dt.Rows[0]["PictureType"].ToString();
    context.Response.BinaryWrite(image);
}
我确实检查并看到
image
不是空的(应该是一个非常大的数组),并且
PictureType
确实保存了以前保存在db中的图片类型。但调用处理程序时仍会看到错误图像图标:

<img src='myhandler.ashx?imgid=someid'/>


发生这种情况的原因是什么?

PictureType列中有什么?在数据库中存储图像=错误。是否可以将它们存储在公用文件夹中,而只将URL存储在数据库中?@MitchWheat,上载图像时,我保留asp.net文件上载控件中的
ContentType
属性。这保存在
PictureType
@arxanas中,我想这也是一种选择。但我的网站现在的工作方式,只会让事情变得比应该的更复杂。我宁愿解决这个问题。您的表是否设置了正确的编码?