调试通过,其他的显示都正常,就是没法显示图片,表格里的图片全部打红叉叉,为什么,大家应该都做过,给点提示好吗

解决方案 »

  1.   

    http://localhost/testall/ReadImage.aspx?id=63
    路径没有问题,我把我代码关键部分贴上来,大家帮我看看呀
    showphoto.aspx
    protected void BindGrid()
    {
    SqlConnection CN = new SqlConnection() ;
    CN.ConnectionString= "data source=localhost;initial catalog=bbs;persist security info=False;user id=sa;Password=sa;
    string sqlstr="select img_pk, img_data from image";
    SqlCommand cm=new SqlCommand(sqlstr,CN);
    CN.Open();
    dg2.DataSource=cm.ExecuteReader();
    dg2.DataBind();
    CN.Close();}
    protected string FormatURL(object strArgument)
    {
    return "ReadImage.aspx?id=" + strArgument.ToString();
    }ReadImage.aspx
    private void Page_Load(object sender, System.EventArgs e)
    {
                   string strImageID = Request.QueryString["id"];
         SqlConnection CN = new SqlConnection() ;
                 CN.ConnectionString= "data source=localhost;initial catalog=bbs;persist security info=False;user id=sa;Password=sa;";
    SqlCommand cm = new SqlCommand("Select image_data,img_contenttype from image Where img_pk='"+strImageID+"'",CN);
    CN.Open();
    SqlDataReader dr=cm.ExecuteReader();
    if(dr.Read())
    {
    Response.Clear(); Response.ContentType = dr["img_contenttype"].ToString();

    Response.BinaryWrite((byte[])dr["img_data"]);
    }
             cm.Connection.Close();
      

  2.   

    Response.ContentType = (string)dr["img_contenttype"];
    Response.OutputStream.Write((byte[])dr["img_data"], 0, (int)dr["imagesize"]);
    //dr["imagesize"]是图片的大小