이전에는 SQL 데이터베이스에 이미지를 삽입하는 데 문제가있었습니다. 이제이 문제를 해결하고 이미지를 sqldatabase에 삽입 할 수있게되었습니다. 이제 데이터베이스 테이블에서 이미지를 검색하는 데 문제가 있습니다. 이 라인에서sql 데이터베이스에서 이미지 가져 오기
showimage.ashx:
<%@ WebHandler Language="C#" Class="ShowImage" %>
using System;
using System.Web;
using System.IO;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
public class ShowImage : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
int empno;
if (context.Request.QueryString["empid"] != null)
empno = Convert.ToInt32(context.Request.QueryString["id"]);
else
throw new ArgumentException("No parameter specified");
context.Response.ContentType = "image/jpeg";
//context.Response.Write("Hello World");
Stream strm = ShowEmpImage(empno);
byte[] buffer = new byte[4096];
int byteSeq = strm.Read(buffer, 0, 4096);
while (byteSeq > 0)
{
context.Response.OutputStream.Write(buffer, 0, byteSeq);
byteSeq = strm.Read(buffer, 0, 4096);
}
}
public Stream ShowEmpImage(int empno)
{
string conn = ConfigurationManager.ConnectionStrings["EmployeeConnString"].ConnectionString;
SqlConnection connection = new SqlConnection(conn);
string sql = "SELECT empimg FROM EmpDetails WHERE empid = @ID";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@ID", empno);
connection.Open();
object img = cmd.ExecuteScalar();
try
{
return new MemoryStream((byte[])img);
}
catch
{
return null;
}
finally
{
connection.Close();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
:
**context.Response.ContentType = "image/jpeg";**
점점 예외
Pls는 내가 데이터베이스 테이블에서 이미지를 검색 할 수있는 방법을 도와 "어떤 매개 변수가 지정되지"여기 내 검색 중 코드입니다. 여기 내 GUI입니다 : 당신이보고있는 예외 실제로 위의 줄에 던져 하나입니다
<asp:Label ID="lblEmpName" runat="server" Text="Employee Name"></asp:Label>
<asp:TextBox ID="txtEName" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblImage" runat="server" Text="Employee Image"></asp:Label>
<asp:FileUpload ID="imgUpload" runat="server" />
<br />
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
onclick="btnSubmit_Click" />
 
<asp:Label ID="lblResult" runat="server" ForeColor="#0066FF"></asp:Label>
<br />
<hr />
<asp:Image ID="Image1" style="width:200px" Runat="server"/>
다시 태그가 C# .NET을 추가 할 수 있습니다. – BalusC