Array
(
)

Gravar 2 imagens no Banco de dados

Dirceu Azevedo
   - 10 dez 2011

Tenho o seguinte código, exibe uma imagem na tela, tenho duas imagens gravadas nao banco qual o procedimento para exibir as duas imagens:
Classe:
/// <summary>
/// Summary description for clsPhoto
/// </summary>
public class clsPhoto
{
public static Stream photo(int ID_TRAVEL)
{
string _connectionString = WebConfigurationManager.ConnectionStrings[VRIConnectionString].ConnectionString;
using (SqlConnection connection = new SqlConnection(_connectionString))
{
string sql = SELECT TRAVEL_IMAGE FROM DEV_TRAVEL WHERE (ID_TRAVEL = @id);
using(SqlCommand cmd = new SqlCommand(sql,connection))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue(@id, ID_TRAVEL);
connection.Open();
object result = cmd.ExecuteScalar();
try
{
return new MemoryStream((byte[]) result);
}
catch
{
return null;
}
}
}
}
}

Handler
<%@ WebHandler Language=C# Class=Handler %>
using System;
using System.Web;
public class Handler : IHttpHandler {

public void ProcessRequest (HttpContext context) {
context.Response.ContentType = text/plain;
context.Response.Write(Hello World);
}

public bool IsReusable {
get {
return false;
}
}
}

Pagina de exibição:
<form id=form1 runat=server>
<div>
<asp:GridView ID=GridView1 runat=server AutoGenerateColumns=False BackColor=#DEBA84
BorderColor=#DEBA84 BorderStyle=None BorderWidth=1px CellPadding=3 CellSpacing=2
DataKeyNames=ID_TRAVEL DataSourceID=dsTravel>
<FooterStyle BackColor=#F7DFB5 ForeColor=#8C4510 />
<Columns>
<asp:BoundField DataField=TRAVEL HeaderText=TRAVEL SortExpression=TRAVEL />
<asp:TemplateField>
<ItemTemplate>
<img src=Image.ashx?ID_TRAVEL=<%#Eval(ID_TRAVEL)%> />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor=#FFF7E7 ForeColor=#8C4510 />
<SelectedRowStyle BackColor=#738A9C Font-Bold=True ForeColor=White />
<PagerStyle ForeColor=#8C4510 HorizontalAlign=Center />
<HeaderStyle BackColor=#A55129 Font-Bold=True ForeColor=White />
</asp:GridView>
<asp:SqlDataSource ID=dsTravel runat=server ConnectionString=<%$ ConnectionStrings:VRIConnectionString %>
SelectCommand=SELECT [ID_TRAVEL], [TRAVEL], [TRAVEL_IMAGE] FROM [DEV_TRAVEL]></asp:SqlDataSource>

</div>
</form>

Grato