Image控件如何能显示保存在数据表Image型字段里的图片?
在GridView的模板列里有一个Image控件,请问如何通过流的方式显示数据表Image字段里的图片,谢谢!
------解决方案--------------------public void ShowPic(int imageid)
{
string connString = "Data Source=LYCEUM_LUO;database=image;uid=sa;pwd=sa ";
string cmdstr = "select * from image where imageID = @imageID ";
SqlConnection conn = new SqlConnection(connString);//初始化数据库连接
SqlCommand cmd = new SqlCommand(cmdstr,conn);
cmd.Parameters.Add( "@imageID ",SqlDbType.Int).Value = imageid;
conn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
Response.OutputStream.Write((byte[])sdr[ "image_data "], 0, (int)sdr[ "image_size "]);
Response.End();
sdr.Close();
conn.Close();
}
这是显示到页面上,显示到Gridview的控件里我也没试过。仅供LZ参考 !