ASP.NET中怎么样从数据库里取出的图片
图片是保存在数据库里的,
数据库里的类型是 Image 的

解决方案 »

  1.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=ECD9AE16-8FF0-4A1C-9B9F-5E8B641CB1B1
      

  2.   

    http://www.0537net.com/blogview.asp?logID=27&cateID=2
      

  3.   

    从SQL Server数据库提取图片并显示在DataGrid
    建立一个页面来读数据库的图片 如ReadPic.aspx
     string picID = Request.QueryString["id"];
       SqlConnection myConnection = new SqlConnection("Data Source=.;database=ImageDB;User Id=sa;Password=sa;");
       SqlCommand myCommand = new SqlCommand("Select  Pic from Person Where ID=" 
        + picID, myConnection);   try
       {
        myConnection.Open();
        SqlDataReader myDataReader;
        myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
        if(myDataReader.Read())
        {
         Response.ContentType = myDataReader["PersonImageType"].ToString();
         Response.BinaryWrite((byte[])myDataReader["PersonImage"]);
        }
        myConnection.Close();
       }
    然后在datagrid的aspx页面如 DataGridPic.aspx放置模板列
    <ItemTemplate>
            <asp:Image Runat=server ID="Image1"
             ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ID") %>' />
          </ItemTemplate>
    就可以了
      

  4.   

    ImageUrl='readpic.aspx?id=<%# DataBinder.Eval(Container.DataItem, "ID") %>' />
      

  5.   

    图片有个 alt 的属性。他就是用来没图片时显示的文字的。