How to retrieve binary image of user from Database with inner join from two table using VB.Net in ASP.Net

Last Reply 11 months ago By Ruben12345

Posted 11 months ago

 

 Private Sub cmd_search_join_Click(sender As Object, e As EventArgs) Handles cmd_search_join.Click
        Call konek_sql_server()
        If txtnik3.Text = "" Then
            MsgBox("Nik Masih Kosong", vbCritical)
        Else
            query_sql_server = "select * from siswa where nik=@nik"
            cmd_sql_server = New SqlCommand(query_sql_server, conn_sql_server)
            cmd_sql_server.Parameters.AddWithValue("@nik", txtnik3.Text)
            dr_sql_server = cmd_sql_server.ExecuteReader
            If dr_sql_server.HasRows = 0 Then
                MsgBox("Nik Is Not Found", vbCritical)
                Call clear_panel_sql_server()
                Response.Redirect(Request.Url.AbsoluteUri)
            Else

                query_sql_server = "select siswa.nama,siswa.jurusan,siswa.image,nilai.nilai1,nilai.nilai2,nilai.nilai3 from siswa inner join nilai on nilai.nik=siswa.nik where siswa.nik=@nik"

                cmd_sql_server = New SqlCommand(query_sql_server, conn_sql_server)
                cmd_sql_server.Parameters.AddWithValue("@nik", txtnik3.Text)
                dr_sql_server = cmd_sql_server.ExecuteReader
                If dr_sql_server.HasRows Then
                    While dr_sql_server.Read

                        txtnama3.Text = dr_sql_server("nama")
                        txtjurusan3.Text = dr_sql_server("jurusan")
                        txtnilai31.Text = dr_sql_server("nilai1")
                        txtnilai32.Text = dr_sql_server("nilai2")
                        txtnilai33.Text = dr_sql_server("nilai3")
                        txtnik3.Enabled = False
                    End While
                End If
            End If
        End If
        cmdupdate3.Enabled = True
        cmddelete3.Enabled = True
        Me.Dispose()
    End Sub

 

Results 1 - 5 of 6 12

Posted 11 months ago

And i was Figure it out with control textbox, but i still failed.

may you try and give me solution with same structure code that i gave ..? thanks


Posted 11 months ago

Hi Ruben12345,

you need to add image control in your aspx page than use below code.

 ImageName.ImageUrl = dr_sql_server("image").ToString()

Retrieve images using a file path stored in database in ASP.Net


Posted 11 months ago

Hi Indresh...

Thanks For Ur Help. I have adding ur suggestion.

and still have any problem, the control was showing images from database , but can not display the image, i think it must declare string convert before data reader (dr_sql_server) 

may you give suggestion to declare string binary convert images based on my position query above


Posted 11 months ago
Indresh says:
ImageName.ImageUrl = dr_sql_server("image").ToString()

 Replace above code with below.

Dim bytes As Byte() = DirectCast(dr_sql_server("image"), Byte())
Dim base64String As String = Convert.ToBase64String(bytes, 0, bytes.Length)
ImageName.ImageUrl = Convert.ToString("data:image/png;base64,") & base64String

 

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html