画像をデータベースに正常に保存できましたが、取得できません...
2 つの列( ) (pk) と( )を含むImageDatabase
単一のテーブルを持つデータベースがあります。Pict
Letter
varchar(50)
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;
}
}
}
私のdefault.aspx
<img id="img1" src="Handler.ashx?Letter='a'" />
私が間違いを犯しているこの点で私を助けてください、