处理程序.ashx
public void ProcessRequest (HttpContext context)
{
string imageid = context.Request.QueryString["ImID"];
SqlConnection connection = new SqlConnection(con);
connection.Open();
SqlCommand command = new SqlCommand("SELECT PhotoStoreTB.Data FROM PhotoStoreTB INNER JOIN UserTB ON UserTB.UserID = PhotoStoreTB.UserID WHERE PhotoStoreTB.UserID ='" + imageid + "'", connection);
SqlDataReader dr = command.ExecuteReader();
dr.Read();
byte[] imagedata = (byte[])dr[0];
context.Response.ContentType = "image";
using (System.IO.MemoryStream str = new System.IO.MemoryStream(imagedata, true))
{
str.Write(imagedata, 0, imagedata.Length);
Byte[] bytes = str.ToArray();
context.Response.BinaryWrite(bytes);
}
connection.Close();
context.Response.End();
}
抛出异常context.Response.End();
{Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}
Aspx 代码
<asp:Image ID="Image2" runat="server" ImageUrl='<%#"Handler.ashx?ImID="+ Eval("PUserID")%>'
Height="115px" Width="115px" CssClass="img-border"/>
我想在数据列表中显示多个图像
数据列表绑定
try
{
ld.Openconnection();
SqlCommand Cmd = new SqlCommand("PGetPropertyByCriteria", ld.con);
Cmd.Parameters.AddWithValue("@StartIndex", 1);
Cmd.Parameters.AddWithValue("@EndIndex", 10);
Cmd.Parameters.AddWithValue("@flag", "Get");
Cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter SqlAda = new SqlDataAdapter(Cmd);
DataSet DsStudentDetails = new DataSet();
SqlAda.Fill(DsStudentDetails);
if (DsStudentDetails.Tables.Count > 0 && DsStudentDetails.Tables[0].Rows.Count > 0)
{
TotalPage = (Int32.Parse(DsStudentDetails.Tables[0].Rows[0]["row"].ToString()) / PageSize) + ((Int32.Parse(DsStudentDetails.Tables[0].Rows[0]["row"].ToString()) % PageSize) > 0 ? 1 : 0);
CurrentRecord = DsStudentDetails.Tables[0].Rows.Count;
DataTable tDataTable = new DataTable("PagingTable");
tDataTable.Columns.Add(new DataColumn("LinkButtonVisible", typeof(bool)));
tDataTable.Columns.Add(new DataColumn("DisplayName", typeof(string)));
tDataTable.Columns.Add(new DataColumn("Value", typeof(string)));
tDataTable.Columns.Add(new DataColumn("LabelVisible", typeof(bool)));
dtlProduct.DataSource = DsStudentDetails.Tables[0];
dtlProduct.DataBind();
}
else
{
DLPAGING.DataSource = null;
DLPAGING.DataBind();
dtlProduct.DataSource = null;
dtlProduct.DataBind();
}
}
catch (Exception ex)
{
ex.ToString();
}
finally
{
ld.Closeconnection();
}
请帮助我将多个图像显示到数据库中的数据列表