DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Pramod Kumar R Guest

    Image from SQL Server to ASP Page



    Dear Friends

    How can i read a image stored in a database (SQL SERVER ) and
    display it in an Asp page.

    Please help me in this

    Bye
    Pramod Kumar R

  2. #2
    karlizzard Guest

    Re: Image from SQL Server to ASP Page

    Generally I would store the image extension in the database, name the image
    in relation to the id of the db record and store all images in a particular
    directory. This way you can test against the img ext field to determine if
    one available and specify the location of the image path/name in your
    scripting.

    KI


    "Pramod Kumar R" <z_pse7@bharatpetroleum.com> wrote in message
    news:3db01f31$1@tnews.web.devx.com...
    >
    >
    > Dear Friends
    >
    > How can i read a image stored in a database (SQL SERVER ) and
    > display it in an Asp page.
    >
    > Please help me in this
    >
    > Bye
    > Pramod Kumar R




  3. #3
    koshy Guest

    Re: Image from SQL Server to ASP Page


    <%@ Language=VBScript %>
    <%
    Response.Expires = -1
    Response.ExpiresAbsolute
    Response.contentType = "image/gif"
    Dim CnToDb
    Set CnToDb=Server.CreateObject("ADODB.Connection")
    Connstring = "DRIVER={SQL Server};SERVER=NEWSERVER;UID=sa;PWD=sqlpass;DATABASE=XManufacturing"
    CnToDb.Open (Connstring)
    txtcustid = Request.Form("txtcustid")

    Dim fld, byteChunk, strNote, Offset, Totalsize, Remainder, NumOfChuncks,
    CurrentRecPos
    Dim FieldSize, FileNumber, HeaderSize, ChunkSize, txtRecCnt, TheFileAcessor

    set rs = Server.CreateObject("ADODB.Recordset")
    if trim(txtcustid)<>"" then
    rs.Open "select a.customer_code Code ,a.customer_name Name,b.photo photo
    from customer_mast a inner join crmcontact b on a.customer_code=b.customer_code
    where b.Customer_Code='"& txtcustid & "'",cntodb,3
    end if


    TempFileBase = "tempfile.tmp"
    pathphysical = Server.MapPath("./photos")
    TempFileDrive = pathphysical & "\"
    TempFileHttp = "./photos/"
    if trim(txtcustid)<>"" then
    if not rs.EOF then
    Set TheFileAcessor = CreateObject("FileAccessor.FileWriter")

    HeaderSize = 78
    ChunkSize = 100

    Set Flds = rs.Fields
    For Each fld In Flds
    FieldSize = fld.ActualSize
    Select Case fld.Name
    Case "Code"
    fldid = trim(fld.Value)
    Case "Name"
    fldName = trim(fld.Value)
    Case "photo"
    on error resume next
    TempFile = TempFileDrive & TempFileBase & "*"
    TheFileAcessor.RemoveFile TempFile
    TempFile = TempFileDrive & TempFileBase & rs(0) & ".gif"
    TheFileAcessor.OpenFile TempFile
    Totalsize = FieldSize - HeaderSize ' Substract
    it from the total size.
    byteChunk = fld.GetChunk(HeaderSize) ' Get rid of the
    header.
    fldPhotocheck = false
    if isnull(byteChunk) or isempty(byteChunk) then
    fldPhotocheck = true
    end if
    TheFileAcessor.WriteToFile byteChunk
    NumOfChuncks = Totalsize \ ChunkSize
    Remainder = Totalsize Mod ChunkSize
    If Remainder > 0 Then
    byteChunk = fld.GetChunk(Remainder)
    TheFileAcessor.WriteToFile byteChunk
    End If
    Offset = Remainder
    Do While Offset < Totalsize
    byteChunk = fld.GetChunk(ChunkSize)
    TheFileAcessor.WriteToFile byteChunk
    Offset = Offset + ChunkSize
    Loop
    TheFileAcessor.CloseFile
    fldPhoto = "<img src='" + TempFileHttp + TempFileBase + rs(0) + ".gif'
    width='100' height='120'></img>"
    if fldPhotocheck then
    fldPhoto = "<img src='" + TempFileHttp + "no.gif' width='100' height='120'></img>"
    end if
    End Select
    Next
    else
    txtmessage = "Customer code " & txtcustid & " could not be found<br>"
    end if
    end if
    %>
    <HTML>
    <HEAD>

    </HEAD>
    <BODY>
    <%Response.Write "<font face='Verdana,Arial' size='1' color='red'>" & txtmessage
    & "</font>"%>
    <form name="frm" action="customer.asp" method="post">
    <table width="100%">
    <tr>
    <td colspan="2"><font face="Verdana, Arial, Helvetica, sans-serif"
    size="1"><b>Customer
    Details</b></font></td>
    </tr>
    <tr>
    <td width="59"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">

    ID</font></td>
    <td width="708"> <font size="1" face="Verdana, Arial, Helvetica, sans-serif">

    <input name="txtcustid" value="<%=fldid%>" size="10">
    <input type="submit" value="Go">
    </font></td>
    </tr>
    <tr>
    <td width="59"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">

    Name</font></td>
    <td width="708"> <font size="1" face="Verdana, Arial, Helvetica, sans-serif">

    <input name="txtcustname" value="<%=fldname%>" size="20">
    </font></td>
    </tr>
    <tr>
    <td width="59"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">

    Photo </font></td>
    <td width="708"> <font size="1" face="Verdana, Arial, Helvetica, sans-serif">

    <%if trim(fldPhoto)="" then
    Response.Write "<img src='" + TempFileHttp + "no.gif' width='100' height='120'></img>"
    else
    Response.Write fldPhoto
    end if%>
    </font></td>
    </tr>
    </table>
    </form>
    </BODY>
    </HTML>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links