Recover image in SQL SERVER and put in a REPEATER list

0

Today I retrieve information from a database and ready a REPEATER, so far everything blz. But I also need to get an image of the database and show in this REPEATER.

Below is how I show the table.

SoIwanttoputacolumnwiththeimage.

Belowclasscodethatretrievesdatafromthedatabase:

publicSqlDataReaderListarClientes(){Stringquery_string="select codcliente,razaosocial,cidade,imagem from cliente";
        SqlConnection conexao = new SqlConnection();
        conexao.ConnectionString = this.string_conexao;
        conexao.Open();

        SqlCommand comando = new SqlCommand();
        comando.CommandText = query_string;
        comando.Connection = conexao;

        SqlDataReader dr = comando.ExecuteReader();

        return dr;
    }

Aspnet Code

 <h2>Lista de clientes</h2>

     <form id="form1" runat="server">



    <div class ="container"
        <div class =" row col-md-6 col-md-offset-2 custyle">



        </div>
    </div>
    <br />
    <br />




    <div class="container">
    <div class="row col-md-6 col-md-offset-2 custyle">


    <asp:Repeater ID="rptCliente" runat="server">

 <HeaderTemplate>

    <table class="table table-striped custab">
      <a href="InsereCliente.aspx" class="btn btn-primary btn-xs pull-right"><b>+</b> Novo</a>
    <tr >
    <td>
        <font ><b>Código</b></font>
    </td>

     <td>
        <font ><b>Nome</b></font>
    </td>

    <td>
        <font ><b>cidade</b></font>
    </td>



    <td align="center">
            <font ><b>Ação</b></font></td>
   </tr>
</HeaderTemplate>



    <ItemTemplate>


     <tr >
           <td>
                 <%# DataBinder.Eval(Container.DataItem, "codcliente") %>   
           </td>
           <td>
                 <%# DataBinder.Eval(Container.DataItem, "razaosocial") %>   
           </td>
           <td>
           <%# DataBinder.Eval(Container.DataItem, "cidade") %>
       </td>


       <td class="text-center">
           <a class='btn btn-info btn-xs' href="#"><span class="glyphicon glyphicon-edit"></span> Editar</a> 
           <a href="#" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-remove"></span> Excluir</a></td>

       </td>
   </tr>
</ItemTemplate>

    </asp:Repeater>
        </div>
        </div>

    </form>

    </body>
</body>

Aspnet screen code C #

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SITE_SERVICO.cliente
{
    public partial class ListaCliente : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            BancoDados.BancoDados bd = new BancoDados.BancoDados();

            SqlDataReader dtCliente = bd.ListarClientes();



            rptCliente.DataSource = dtCliente;
            rptCliente.DataBind();




        }
    }
}

Can anyone help me?

    
asked by anonymous 16.06.2017 / 04:27

2 answers

0

I was able to solve it.

I used bytes [] to solve.

The result of the database search was placed in a SqlDataReader drCartaoProfessional and then done as follows:

byte [] bytes = (byte []) drCartaoProfessional ["image"];  string base64String = Convert.ToBase64String (bytes, 0, bytes.Length);  

Then in an html IMG, I set the src property to the URL.

    
08.10.2017 / 18:24
0

If you saved the image path in your bank, you just need to add the Image component to your repeater:

<td>
    <asp:Image ID="Image1" height="32" width="32" runat="server" ImageUrl='<%# Eval("ImageUrl") %>' />
</td>

If you only have the image name ex: "user_26.jpg" then you will have to put the path inside the repeater or an ItemDataBound .

So:

<td>
    <asp:Image ID="Image1" height="32" width="32" runat="server" ImageUrl="../imagens/user/'<%# Eval("ImageUrl") %>'" />
</td>

Show images in Repeater control has a related question that can help you if you still need it.

    
16.06.2017 / 14:37