大神帮帮忙看看
//SQLHelper.cs
//从数据库中读取image类型图片并且显示到控件上
public bool ShowImage(string sql, System.Web.UI.WebControls.Image img1)
{
SqlConnection imgConn = new SqlConnection(connectionString);
try
{
SqlCommand cmd = new SqlCommand(sql, imgConn);
imgConn.Open();
byte[] b = (byte[])cmd.ExecuteScalar();
if (b.Length > 0)
{
MemoryStream stream = new MemoryStream(b, true);
stream.Write(b, 0, b.Length);
Image img = Image.FromStream(stream);
//img.ImageUrl = new System.Drawing.Bitmap(stream);
stream.Close();
}
return true;
}
catch
{
img1 = null;
return false;
}
finally
{
imgConn.Close();
}
}
//后台
//显示图片
sp.ShowImage("Select Photo From Description1 Where id='" +this.id.Text + "'", imgphoto);