Stream Database Photo as ASPX page...





8
Date Submitted Thu. Jan. 11th, 2007 9:47 AM
Revision 1 of 1
Scripter Casper42
Tags ASPX | SQL | VB.NET
Comments 2 comments
This routine will get an image stored in a SQL database (IBM Informix shown here) as a BLOB and return it to the screen.

To place this on an HTML page simply add

I have an MD5 hashed version as well, but can't share that...(So you can have encrypted id's passed)

Have fun,
Jeremy

Imports IBM.Data.Informix

Public Class ShowPicture
    Inherits System.Web.UI.Page

    Private Sub ShowPhoto(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Read in the employee ID from the querystring
        Dim iEmployeeID
        iEmployeeID = Request.QueryString("ID")

        Dim conIfx As New IfxConnection

        'Set Informix Connection String
        conIfx.ConnectionString = "Server=yourserver;DataBase=yourdatabase;User Id=username;Host=dbhost;Protocol=onsoctcp;service=yourservice;Password=yourpassword;"

        Dim strSQL As String
        strSQL = _
                  "SELECT profile_rec.id, profile_rec.photo " & _
                  "FROM profile_rec " & _
                  "WHERE profile_rec.id='" & iEmployeeID & "'"

        Dim cmdIfx As New IfxCommand(strSQL, conIfx)

        'Open Informix Connection
        conIfx.Open()

        'Delcare Informix Data Reader
        Dim drIfx As IfxDataReader

        'Execute Informix Reader
        drIfx = cmdIfx.ExecuteReader()

        If drIfx.Read Then
            Response.ContentType = "image/jpeg"
            Response.BinaryWrite(drIfx.Item("photo"))

        End If

        'Clean up...
        drIfx.Close()
        drIfx = Nothing

        conIfx.Close()
        conIfx = Nothing

    End Sub
End Class
 

Jeremy Edmiston

Comments

Comments Note
Sun. Feb. 11th, 2007 9:21 PM    Helper jbplou
Comments Thank you
Thu. Jul. 5th, 2007 8:31 AM    Beginner babakzawari

Voting