代码如下:
        SqlConnection conn = new SqlConnection(strconn);
        conn.Open();
        string strsql = "select * from [File]";
        SqlCommand cmd = new SqlCommand(strsql, conn);
        SqlDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            Response.ContentType = dr["PicType"].ToString();
            Response.BinaryWrite((byte[])dr["Pic"]);
        }
        conn.Close();

解决方案 »

  1.   

    可能数据库里存的数据有错误吧
    试下
    Response.ContentType = "application/octet-stream";
    Response.BinaryWrite((byte[])dr["Pic"]); 
    Response.End();
      

  2.   

    while (dr.Read()) ......
    请教楼主,这样子循环的作用是什么?
      

  3.   

    SqlConnection conn = new SqlConnection(strconn); 
            conn.Open(); 
            string strsql = "select * from [File]"; 
            SqlCommand cmd = new SqlCommand(strsql, conn); 
            SqlDataReader dr = cmd.ExecuteReader(); 
           
                    if(dr.Read()) //只读取第一行
            { 
                 Response.ContentType = dr["PicType"].ToString(); //这里要保证是"image/jpg"的格式;
                 Response.BinaryWrite((byte[])dr["Pic"]); 
            }else
            {
                 Response.Write("没有任何图片");//帮你检查一下是否取到值
            }
            conn.Close();
            Response.End();
      

  4.   

    如果有时间,可以参考一下:http://blog.csdn.net/insus/archive/2008/01/20/2055033.aspx
      

  5.   

    在同一个页面上只能显示一个图片
    因为页面也是文件,就好像同一张图片不能同时显示另外一张图片是一个道理如果想显示多张图片请使用下面的方式<img src="url+图片1-id参数"/>
    <img src="url+图片2-id参数"/>
    在src中通过url+?image=id的方式传递参数然后显示图片的页面通过参数得到对应的图片显示一张图片但是请求页面因为有多个img所以可以显示多张图片