前台用的repeater<table><tr><td><img id="myimg"></td></tr><tr><td><%#eval('name')></td></tr>
后台
datatable dt=sqlhelper.getdata();
repeater.datasource= dt.deflautview;
repeater.databind();以上是简写的
图片的字段名是'photo'是二进制格式,请问如何绑定数据的时候,将photo字段转化成图片放在td里?

解决方案 »

  1.   


      byte[] photoByte = null; 
                                int ArraySize; 
                                photoByte = (byte[])dr["Photo"]; 
                                ArraySize = photoByte.GetUpperBound(0); 
                                System.IO.MemoryStream ms = new System.IO.MemoryStream(ArraySize + 1); 
                                ms.Write(photoByte, 0, ArraySize + 1); 
                                imgPicFace.ImageUrl = (System.Drawing.Bitmap)System.Drawing.Image.FromStream(ms); 
                                ms.Close(); 
      

  2.   

    二进制图片存取if (this.FileUpload1.HasFile)
      {
      string strPath = FileUpload1.FileName;
      try
      {
      string extension = Path.GetExtension(File1.PostedFile.FileName).ToUpper();
      string fileName = DateTime.Now.ToString("yyyyMMddhhmmss");
      strPath = strPath.Substring(strPath.LastIndexOf("\\") + 1);
      FileUpload1.SaveAs.SaveAs(Server.MapPath("../UploadFile/")+fileName + extension);
      strPath = fileName + extension;
      using(SqlConnection conn =new SqlConnection(""))
      {  
      conn .Open();
      string sql = "";
      SqlCommand cmd = new SqlCommand(sql, conn );
      cmd.ExecuteNonQuery();
      conn.Close();
      }  }
      catch()
      {
      }
      }
     一般保存路径二进制使用
    Stream s = FileUpload1.PostedFile.InputStream;
    Byte[] buffer= new Byte[FileUpload1.PostedFile.ContentLength];
    s.Read(buffer,0,FileUpload1.PostedFile.ContentLength);
     string strsql = "insert into Tempimage(images,names)values(@ImageData,@names)";
      SqlCommand cmd= new SqlCommand(strsql, conn);
      cmd.Parameters.Add("@ImageData", SqlDbType.Image);
      cmd.Parameters.Add("@names", SqlDbType.VarChar);
      cmd.Parameters["@ImageData"].Value = buffer;
      cmd.Parameters["@names"].Value = "";
      cmd.ExecuteNonQuery();显示
     Image1.ImageUrl="Photo.aspx?id="+Request.QueryString["id"];
    photo.aspx
    int Id=Request.QueryString["id"]==null?0:int.Parse(Request.QueryString["id"].ToString());
    using(SqlConnection conn=new SqlConnection())
    {
    conn.ConnectionString="";  
    string strSql="select * from A where Id='"+Id+"'";  
    SqlCommand cmd=new SqlCommand(strSql,conn) ;
    conn.Open();
    SqlDataReader reader=cmd.ExecuteReader();
    if(reader.Read())
    {
    Response.ContentType = "application/octet-stream";
    Response.BinaryWrite((Byte[])reader["Photo"]);
    }
    Response.End();
    }
      

  3.   


            FileStream fs = new FileStream(Server.MapPath("images/002.jpg"),FileMode.Open);
            byte[] b = new byte[fs.Length];
            fs.Read(b, 0, b.Length);
            fs.Close();
            fs.Dispose();
    //上面换成你从数据库读取出来的值
            Response.BinaryWrite(b);
      

  4.   

    LZ ,你的问题我刚解决  看这个http://maticsoft.blog.163.com/blog/static/18273741020112224534589/
      

  5.   

    http://maticsoft.blog.163.com/blog/static/18273741020112224534589/
      

  6.   

    参考:
    http://www.cnblogs.com/insus/articles/1430434.html