这是以前写的一段读取image的代码
<script runat=server>
private void Page_Load(Object sender, System.EventArgs e)
{
string imgid =Request.QueryString["imgid"];
string connstr="server=(local);database=ImageStore;Trusted_Connection=yes";
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();
}
</script>