我想实现的功能是:从SQL SERVER的image字段中读取图片,然后显示出来.是以二进制保存图片的.
下面是源代码,但是为什么运行后会没能正常显示出图片呢,也没报错.请问是什么原因,怎么解决?
private void get_proimage()
{
SqlConnection conn=new SqlConnection(path);
try
{
SqlCommand cmd=new SqlCommand("sp_listproimg",conn);
cmd.CommandType=CommandType.StoredProcedure;
SqlDataReader dr=cmd.ExecuteReader();
if(dr.Read())
{
Response.ContentType = dr["imgtype"].ToString();
Response.BinaryWrite( (byte[]) dr["imgdata"] );
}     
}
catch(Exception error)
{
Response.Write(error.Message.ToString());
}
finally
{
conn.Close();
}
}