HOW TO: Read and Write BLOB Data by Using ADO.NET with Visual C# .NET
http://support.microsoft.com/default.aspx?kbid=309158

解决方案 »

  1.   

    <%@Page language="C#"%>
    <%@import namespace="System.Data"%>
    <%@import namespace="System.Data.SqlClient"%>
    <script language="C#" runat="server">
    public void Page_Load(Object o, EventArgs e)
    {
    int ImgID = Convert.ToInt32(Request.Params["id"]);
    string connStr = ConfigurationSettings.AppSettings["ConnectionString"];
    SqlConnection conn = new SqlConnection(connStr);
    string sql = "select * from t_imgs where id = @ImgID";
    SqlCommand cmd = new SqlCommand(sql, conn);
    cmd.Parameters.Add("@ImgID", SqlDbType.Int).Value = ImgID;
    conn.Open();
    SqlDataReader read = cmd.ExecuteReader();
    read.Read();
    Response.ContentType = (string)read["type"];
    Response.OutputStream.Write((byte[])read["imgData"], 0, (int)read["imgSize"]);
    Response.End();
    conn.Close();
    }
    </script>
      

  2.   

    HOW TO: Copy a Picture from a Database Directly to a PictureBox Control with Visual C#
    http://support.microsoft.com/default.aspx?kbid=317701