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

Last Reply 5 months ago By Ruben12345

Posted 5 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

 

Posted 5 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?aff_id=108