private void ImageOutput()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationSettings.AppSettings["conn"];SqlCommand comm = new SqlCommand("select * from TempTable ",conn);
comm.CommandType = CommandType.Text;conn.Open();SqlDataReader dr = comm.ExecuteReader();if(dr.Read())
{
Response.Clear();
Response.ContentType=dr["imagetype"].ToString();
Response.BinaryWrite((byte[])dr["images"]);
}

dr.Close();
conn.Close();
}以上是我的.cs文件,.aspx文件中没有任何控件。请问怎么显示数据库图片啊?

解决方案 »

  1.   

    编译有抱错说我的 Response.BinaryWrite((byte[])dr["images"]); 中的images字段有错误。
      

  2.   

    你的images是什么类型的字段呢??
      

  3.   

    string str=System.Configuration.ConfigurationSettings.AppSettings["cn"];
    SqlConnection cn=new SqlConnection(str);
    SqlCommand cmd=new SqlCommand();
    cmd.CommandText="select Cover from Books where BookGuid='"+this.Request["ImageID"]+"'";
    cmd.Connection=cn;
    cn.Open();
    this.Response.ContentType="image/*";
    SqlDataReader dr=cmd.ExecuteReader();
    while(dr.Read())
    {
    this.Response.BinaryWrite((byte[])dr["Cover"]);
    }
    cn.Close();
      

  4.   

    我的images是image类型的字段。
      

  5.   

    现在显示的是 GIF89a? 就是不能正确显示图片。
      

  6.   


    這是asp+sql2000的,請參考。
    <!--#include file="conn.asp" -->
    <%
    set rs1=Server.CreateObject("Adodb.Recordset")
    rs1.open "select * from test where id='" & Request("id") & "'",conn,1,1
    'do while not rs.eof%><%
    response.ContentType="image/*"
    'response.binarywrite rsTest(0).getchunk(rsTest(0).actualsize)response.binarywrite rs1("photo").getchunk(rs1("photo").actualsize)
    rs1.close
    'rs.movenext
    'loop
    'Response.ContentType="*/*"
    'Response.write "OK"
    %>
      

  7.   

    這是C# + sql2000
    ...
    try
    {
    MemoryStream buf=new MemoryStream((byte[])_row[MemberData.Field_Photo]);
    Image img=Image.FromStream(buf,true);
    picPhoto.Image=img;
    }
    catch
    {
    }
      

  8.   

    我也读不出图片来
    程序如下:
    //string imgid = Request.QueryString["imgid"];
            string connstr = "Data Source=LENOVO-9D9FA7CF;Initial Catalog=TestDataBase;Integrated Security=True";
            //Context.GetConfig("appSettings"))["connstr"];
            string sql = "SELECT * FROM test where id='1';" ;
            SqlConnection connection = new SqlConnection(connstr);
            SqlCommand command = new SqlCommand(sql, connection);
            connection.Open();
            SqlDataReader dr = command.ExecuteReader();
            if (dr.Read())
            {
                Response.ContentType = dr["FImage"].ToString();
                Response.BinaryWrite((byte[])dr["FImage"]);
            }
            connection.Close();
    帮看看!