我成功地将图像存储在数据库中,但我无法检索它......
我有ImageDatabase
一个Pict
包含两列Letter
(varchar(50)
)(pk)和Picture
(image
)的表的数据库,
我的Handler.ashx
代码:
using System;
using System.Web;
using System.Data.SqlClient;
using System.IO;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string L = (context.Request.QueryString["Letter"]);
SqlConnection connection = new SqlConnection();
connection.ConnectionString = @"Data Source=RANJHANI-PC\SQLEXPRESS;Initial Catalog=ImageDatabase;Integrated Security=True";
string sql = "SELECT Picture FROM Pict WHERE Letter = @Ltr";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.Parameters.AddWithValue("@Ltr", L);
connection.Open();
byte[] bytes = (byte[]) cmd.ExecuteScalar();
context.Response.ContentType = "image/jpeg";
context.Response.BinaryWrite(bytes);
connection.Close();
}
public bool IsReusable {
get {
return false;
}
}
}
我的默认.aspx
<img id="img1" src="Handler.ashx?Letter='a'" />
请在这方面帮助我,我犯了错误,