http://expert.csdn.net/Expert/topic/1424/1424660.xml?temp=.794079

解决方案 »

  1.   

    使用流读取附件,转换成byte数组,存入binary字段,使用的时候可以直接使用流读取,或者使用byte数组读取
      

  2.   

    Retrieving images from database
    Now, let us read the images from the database we stored previously. Here, we will output the image directly to the browser. You can instead save it as a file or do whatever you want. 
    private void Page_Load(object sender, System.EventArgs e)
    {
    string imgid =Request.QueryString["imgid"];
    string connstr=((NameValueCollection)
    Context.GetConfig("appSettings"))["connstr"];
    string sql="SELECT imgdata, imgtype FROM ImageStore WHERE id = "
    + imgid;
    SqlConnection connection = new SqlConnection(connstr);
    SqlCommand command = new SqlCommand(sql, connection);
    connection.Open();
    SqlDataReader dr = command.ExecuteReader();
    if(dr.Read())
    {
    Response.ContentType = dr["imgtype"].ToString();
    Response.BinaryWrite( (byte[]) dr["imgdata"] );
    }
    connection.Close();
    }