SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying images from the database.

    Hi all,

    I want to search images and display it with my search result.

    Below is the code I use but it is not working it is giving me errors.

    I will appreciate any help.

    my search code is working but to display images from database is the problem.


    set rsSearch = Server.CreateObject("ADODB.Recordset")
    sql= "SELECT File_Data" & "FROM [registration] " & "WHERE City LIKE '" & Replace(request.Form("txtsearch"), "'", "''") & "%' "
    strSearch = "SELECT Brief,Area,City,Country,Telephone" & "FROM [registration] " & "WHERE City LIKE '" & Replace(request.Form("txtsearch"), "'", "''") & "%' "
    rsSearch.open strSearch,strSql,strconn,3,3

    %>

    <%
    On error resume next
    rsSearch.movefirst
    while Not rsSearch.eof
    %>
    </p>
    <table>
    <tr>
    <td height="20" colspan="4" class="fontbold"> <%=rsSearch("Brief")%> </td>
    </tr>
    <tr>
    <td width="217" height="20" class="font"> <%=rsSearch("Area")%> </td>
    <td width="99" class="font"> <%=rsSearch("City")%> </td>
    <td width="94" class="font"> <%=rsSearch("Country")%> </td>
    <td width="225" class="font"> <%=rsSearch("Telephone")%> </td>
    <td width="200">
    <%
    if not (rsSearch.EOF and rsSearch.BOF) then
    PicSize = rsSearch("File_Data").ActualSize
    if PicSize > 0 then
    Response.BinaryWrite rsSearch("File_Data").GetChunk(rsSearch("File_Data ").ActualSize)
    End if
    End If

    response.End

    if rsSearch.eof then
    respond.end
    else
    Response.ContentType ="image/jpeg"
    Response.BinaryWrite(rsSearch("File_Data"))
    end if
    %>
    </td>

    </tr>
    <%

  2. #2
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what is the error message ?

  3. #3
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Error Type:
    Provider (0x80020005)
    Type mismatch.
    /property/html/property_shop1.asp, line 187

    This is the line

    rsSearch.open strSearch,strSql,strconn,3,3


    This is what I did.

    set rsSearch = Server.CreateObject("ADODB.Recordset")
    sql= "SELECT File_Data" & "FROM [registration] " & "WHERE City LIKE '" & Replace(request.Form("txtsearch"), "'", "''") & "%' "
    strSearch = "SELECT Brief,Area,City,Country,Telephone" & "FROM [registration] " & "WHERE City LIKE '" & Replace(request.Form("txtsearch"), "'", "''") & "%' "

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    TWO SQL commands (strSearch and sql) in the one recordset.open call? Surely not!
    Ian Anderson
    www.siteguru.co.uk

  5. #5
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please I need your help this is the first time I am searching the database for images.

  6. #6
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You need to decide WHICH command you want to use with rsSearch.open ... sql or strSearch. You can't use both.

    http://www5.brinkster.com/hiflyer/db/dbtest3.asp
    Ian Anderson
    www.siteguru.co.uk

  7. #7
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to use strSearch.

  8. #8
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Then use it.

    rsSearch.open strSearch,strconn,3,3

    Did you even look at the link I posted?
    Ian Anderson
    www.siteguru.co.uk

  9. #9
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I looked at it but it does not have search images from the database

  10. #10
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Without knowing what tables/fields you have in your database, what datatypes they are, and some example data then we're pretty stuck to try and help you.
    Ian Anderson
    www.siteguru.co.uk

  11. #11
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So can I upload the database to you now.

    I Will do that with the asp page that has the code.

    Thanks

  12. #12
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have attached the files.

    index page is the page with the search form.

    when you open the html you will find the html folder and the database also you will see the code I have done.

    Thanks
    Attached Files Attached Files

  13. #13
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sql= "SELECT File_Data" & "FROM [registration] " & "WHERE City LIKE '" & Replace(request.Form("txtsearch"), "'", "''") & "%' "

    This probably isn't the whole problem, but why the 1st "&"??? And no space before the "FROM"? the output of this string will be:

    SELECT File_DataFROM [registration] WHERE City LIKE 'whatever%'

    That's not gonna fly. The line number you're being given for the error just means there's something wrong in your sql statement.

  14. #14
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok Please can you help. I will really appreciate.

  15. #15
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I think the advice is self-explanatory. Your SQL is malformed, but the error doesn't occur until you try the use it.

    Code:
    Need a space here...........
    sql= "SELECT File_Data" & "FROM [registration] " & "WHERE City LIKE '" & Replace(request.Form("txtsearch"), "'", "''") & "%' "
    I'd go further and ask, why do you have so many unnecessary & in your SQL statement?

    Code:
    Same as above with space....
    sql= "SELECT File_Data" & " FROM [registration] " & "WHERE City LIKE '" & Replace(request.Form("txtsearch"), "'", "''") & "%' "
    
    can become
    
    sql= "SELECT File_Data FROM [registration] WHERE City LIKE '" & Replace(request.Form("txtsearch"), "'", "''") & "%'"
    Ian Anderson
    www.siteguru.co.uk

  16. #16
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK Thanks.
    I was actually doing search on the database and that one works.

    It was when I wanted the images to display beside the search results that I started getting problems.

    Apart from the line where I declear "sql"

    the other line of codes works well but I am just having issue displaying the images beside the search results.


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
  •