我在一个页面中用了一个datalist,其中放了一个image
在后台中谢了image.imageUrl="readPic.aspx?afterID="+id;
在readPic页面中,写了一下代码。读不出啊,大家快看看
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Drawing.Imaging;namespace adb
{
/// <summary>
/// readPic 的摘要说明。
/// </summary>
public class readPic : System.Web.UI.Page
{

        adb.Access.DBConnection dbcon=new adb.Access.DBConnection();
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
string afterID=Page.Request.QueryString["afterID"];
string sql="select questionPic from AfterServices where afterID='"+afterID+"'";
SqlConnection con=dbcon.getConnection();
con.Open();
SqlCommand com=new SqlCommand(sql,con);
SqlDataReader dr=com.ExecuteReader();
while(dr.Read())
{
byte[] buffer=(byte[])dr["questionPic"];
Page.Response.Clear();
Page.Response.ContentType="image/gif";
Response.BinaryWrite(buffer);
Page.Response.End();
}
con.Close();
}
}
}
}

解决方案 »

  1.   

    AfterServices表中的afterID字段是字符型的吗?不是的话
    string sql="select questionPic from AfterServices where afterID="+afterID;
      

  2.   

    image.imageUrl="readPic.aspx?afterID="+id
    readPic.aspx明明是一个网页文件,当然显不出来,换一图像文件不就行了!
    例如:image.imageUrl="readPic.gif";
      

  3.   

    afterID他是字符类型的,char。当然是用web页面了
      

  4.   

    在地址栏输入http://xxxx/xxxx/readPic.aspx?afterID=xxxx
    看看能否正常显示
      

  5.   

    if (dr.Read())
    {
    Response.ContentType = "image/jpeg";
    Response.BinaryWrite((byte[])dr["questionPic"]);
    Response.End();
    }
      

  6.   

    我知道了,很有可能是把图片提交到数据库的时候,图片字段的格式不对。或者提交上去的格式不对。我看数据库里正确的显示(...),可是现在显示的是很多乱码
    我的图片字段是image,这个不错。
    我写了两个页面,一个页面,一个数据连接层。
    页面里这样写。
    string path=this.questionPic.PostedFile.FileName;
    int size=this.questionPic.PostedFile.ContentLength;
    string picType=this.questionPic.PostedFile.ContentType;
    Stream picStream=this.questionPic.PostedFile.InputStream;
    byte[] content=new byte[size];
    int status=picStream.Read(content,0,size);然后我调用数据连接层的方法,这里写了一个存储过程图片类型也是image。但是我们给这个变量传参数时他应该是byte〔〕,对吧??我就是把content传进去的。
    如果数据连接和表示页面在一个页面。它就是可以的
    我怀疑是int status=picStream.Read(content,0,size);有问题,当把content直接传过去时,数据连接层,可能认为每有这句。