0

I' m new in this, also I'm new in Visual Basic and Sql Server, and I'm Chile... Well, I have a question, I've been thinking for several days and can not solve. I need to show an image in a web form of a client when he wants to see your information.

For that, I have the next sources:

Table Client

email(varchar), nameClient(varchar), nameImage(varchar)

Table Image

nameImage(varchar), image(image)

I have the next proc:

select c.email, c.nameClient, i.image
from Client as c join Image as i on c.nameImage=i.nameImage

In asp.net, I have a web Form as VerCliente.aspx, and in VerCliente.aspx.vb I have this:

Partial Class Default19
Inherits System.Web.UI.Page

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    MostrarNombreCliente.Text = Session("correo")


End Sub

Protected Sub BotonMostrarPerfil_Click(sender As Object, e As EventArgs) Handles BotonMostrarPerfil.Click
    Dim numero As Integer

    Dim dvSql As Data.DataView = DirectCast(SqlDataSource1.Select(DataSourceSelectArguments.Empty), Data.DataView) 

'of this way I do the connection to BD'

    If dvSql.Count > 0 Then
        numero = 1

'to display the information in the textbox Iam occupying session variables'

        Session("email") = dvSql(0).Item(0)
        MostrarEmail.Text = Session("email")

        Session("nombre") = dvSql(0).Item(1)
        MostrarNombreCompleto.Text = Session("nombre")

in VerCliente.aspx I have this , and I would display the image on it

asp:Image ID="MostrarImagen" runat="server" Height="191px" Width="270px" /

but I dont know how to occupy session variables here

        MostrarImagen.ImageUrl....(I dont know How )

I tried this but it does not work

        Session("imagen") = dvSql(0).Item(2)
        MostrarImagen.ImageUrl.ImageUrl =  Session("imagen")





    End If
End Sub

End Class

thank....bye!!!

Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
  • you an use base64 http://stackoverflow.com/questions/13863631/vb-net-display-an-image-in-image-control-from-filepath-saved-in-an-access-datab – Ravi May 21 '15 at 08:45
  • 1
    saving image url in a session variable will be more suitable. – yogihosting May 21 '15 at 10:20
  • An image size can be huge and saving it in the session could take up memory if you have a lot of users. Personally, I would store the image on the harddrive and save the filename in the database. You could then store the filename in the session if you need to. – the_lotus May 21 '15 at 13:22

1 Answers1

0

Well, after of I'm trying many times, finally I can to resolve my problem, howerer I think that the way that I did the new solution is quite different to how I had posed my problem, but the important is that my solution works fine...

Here is my solution, I hope that can to be of utility for you..

Thank for your comments!!!

Session("imagen") = dvSql(0).Item(8)

        If (Context.Session("imagen")) IsNot Nothing Then
            Dim image As Byte() = DirectCast(Context.Session("imagen"), Byte())

           Dim base64String As String = Convert.ToBase64String(image, 0, image.Length)
            Image1.ImageUrl = Convert.ToString("data:image/png;base64,") & base64String
            Image1.Visible = True
        End If