0

画像をデータベースに正常に保存できましたが、取得できません...

2 つの列( ) (pk) と( )を含むImageDatabase単一のテーブルを持つデータベースがあります。PictLettervarchar(50)Pictureimage

私の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'" />

私が間違いを犯しているこの点で私を助けてください、

4

1 に答える 1

0

BinaryWrite の前に応答ストリームをクリアしてみてください

context.Response.Clear();
context.Response.ContentType = "image/jpeg";
context.Response.BinaryWrite(bytes);
context.Response.End();
于 2013-04-28T14:50:04.140 に答える