我希望将一个图片jpeg,gif等文件上传到updateprofilepicture页面上的SQL数据库中.然后在配置文件页面上,我想从sql数据库中检索图像并将其显示在Asp: Image控件中.我有很多代码尝试这样做,但
// ProcessRequest method of Image.ashx long imageId = Convert.ToInt64(Request.QueryString["ImageId"]); using (var conn = new SqlConnection(connectionString)) using (var command = new SqlCommand( "SELECT ImageFile FROM ImageTable WHERE ImageId = @ImageID", conn)) { command.Parameters.Add("@ImageID", SqlDbType.Int).Value = imageId; conn.Open(); Response.ContentType = "image/gif"; Response.BinaryWrite((byte[]) command.ExecuteScalar()); }
然后在您的页面中使用图像:
<asp:Image id="Image1" runat="server" ImageUrl="Image.ashx?ImageID=12"/>