在asp.net C#中请问如何读取数据库中一个图片的字段并显示在image控件中啊,
string connstr="server=localhost;database=test;User Id=sa;pwd=123456;";
string sql="SELECT 图片 FROM 表 WHERE id ='0002' ";
SqlConnection connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
SqlDataReader dr = command.ExecuteReader();
if(dr.Read())
{
Response.ContentType = "image/gif";
// Response.BinaryWrite( (byte[]) dr["图片"] ); Response.BinaryWrite((byte[]) dr["图片"] );
}
connection.Close();
如果这样显示图片,只能在一个新的页面上显示,现在我想把这个照片显示在页面的一个image控件上,请问该如何做啊,还望高人指点,谢谢!!!
string connstr="server=localhost;database=test;User Id=sa;pwd=123456;";
string sql="SELECT 图片 FROM 表 WHERE id ='0002' ";
SqlConnection connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
SqlDataReader dr = command.ExecuteReader();
if(dr.Read())
{
Response.ContentType = "image/gif";
// Response.BinaryWrite( (byte[]) dr["图片"] ); Response.BinaryWrite((byte[]) dr["图片"] );
}
connection.Close();
如果这样显示图片,只能在一个新的页面上显示,现在我想把这个照片显示在页面的一个image控件上,请问该如何做啊,还望高人指点,谢谢!!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货