Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Help with ASP

Options
  • 09-11-2005 10:11pm
    #1
    Registered Users Posts: 1,488 ✭✭✭


    Hello,

    Im making myself a website and i'm putting a photos page on it. I am using paging to display the photos 10 per page, but i'm getting an error that i cant seem to debug...

    Anyone have any ideas

    The error is from the red underlined line...
    Response.Write vbCrLf

    ' Continue with a title row in our table
    Response.Write "<table border=""0"">" & vbCrLf

    ' Show field names in the top row
    Response.Write vbTab & "<tr>" & vbCrLf
    For I = 0 To oRS.Fields.Count - 1
    response.write "</tr>"
    Response.Write "<tr><td><a href='displaygroup.asp?group=" & oRS("group") & "'><img src='photos/" & oRS("photo") & ".jpg' width='80' height='60'></a>"
    Response.Write "<br><a class='photodetail' href='displaygroup.asp?group=" & oRS("group") & "'>" & oRS("group") & "</a>"
    Response.Write "</td>"
    Next 'I
    Response.Write vbTab & "</tr>" & vbCrLf

    ' Loop through our records and ouput 1 row per record
    iRecordsShown = 0
    Do While iRecordsShown < iPageSize And Not oRS.EOF
    Response.Write vbTab & "<tr>" & vbCrLf
    For I = 0 To oRS.Fields.Count - 1
    Response.Write vbTab & vbTab & "<td>"
    Response.Write oRS.Fields(I)
    Response.Write "</td>" & vbCrLf
    Next 'I
    Response.Write vbTab & "</tr>" & vbCrLf

    ' Increment the number of records we've shown
    iRecordsShown = iRecordsShown + 1
    ' Can't forget to move to the next record!
    oRS.MoveNext
    Loop

    ' All done - close table
    Response.Write "</table>" & vbCrLf
    End If

    The fields are present in the database and contain text... the photo files (*.jpg) are in the correct folder (but I dont think that really matters...)

    My SQL string to select from the database is
    strSQL = "SELECT DISTINCT group AND photo FROM photo WHERE pass='mypassword'"
    set oCN = server.createobject("ADODB.Connection")
    oCN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
    & Server.Mappath("db/homepg.mdb")
    set oRS= oCn.execute( strSQL )

    Thanks in advance for any help


Comments

  • Moderators, Politics Moderators Posts: 39,788 Mod ✭✭✭✭Seth Brundle


    Straight off, I can't see anything odd.
    What is the exact error?


  • Moderators, Science, Health & Environment Moderators Posts: 8,950 Mod ✭✭✭✭mewso


    Whoops misread the code.


  • Registered Users Posts: 640 ✭✭✭Kernel32


    strSQL = "SELECT DISTINCT group, photo FROM photo WHERE pass='mypassword'"

    Also if you are exclusively using IIS5 or IIS6 then don't do..
    server.createobject("ADODB.Connection")
    Instead use
    Createobject("ADODB.Connection")

    Server was only needed in IIS4 on NT so the calling context would flow correctly. With IIS5 and COM+ it was no longer needed. In fact you will experience a performance hit when using it because it uses legacy code that it shouldn't need to execute. After all these years you would think this would have become common knowledge but I see it again and again.


  • Registered Users Posts: 629 ✭✭✭str8_away


    Kernel32 wrote:
    Also if you are exclusively using IIS5 or IIS6 then don't do..
    server.createobject("ADODB.Connection")
    Instead use
    Createobject("ADODB.Connection")

    Server was only needed in IIS4 on NT so the calling context would flow correctly. With IIS5 and COM+ it was no longer needed. In fact you will experience a performance hit when using it because it uses legacy code that it shouldn't need to execute. After all these years you would think this would have become common knowledge but I see it again and again.

    Intresting fact but take a look on these two web sites http://www.4guysfromrolla.com/webtech/043099-1.shtml and http://www.asp101.com/tips/index.asp?id=88 you will see why there are reasons to use server.createobject.

    Event Viewer is great debug tool when your site is big sometime it is hard to fine the bug. Imagen a client rings up saying there are something wring with site but they cannot remember what they did for you to duplicate that error. With event viewer ou can simply scroll down the list and find out what the error was and what cause it.


  • Closed Accounts Posts: 2,046 ✭✭✭democrates


    I'd temporarily try each part of the output string on it's own and see which bit is failing, the concatenation and quotes/double quotes look ok at a glance.

    EG
    Response.Write "<tr><td><a href='displaygroup.asp?group="
    Response.Write oRS("group")

    etc

    Of course the table display will be gimped during this debug but you should see in view source how far it got.
    Also check try
    response.write oRS.recordcount
    to see that you're getting records returned.


    As an aside you may be interested in a function I used to use:
    Sub wl(fieldStr)
    '

    ' Write out a line ending with a carriage return & line feed charachter
    if fieldStr = "" then
    response.write vbCrLf
    else
    response.write fieldStr & vbCrLf
    end if
    end Sub

    To use it :

    call wl('mystring')

    This was pure laziness to save adding the carriage return and line feed to keep the output human-readable each time I was writing out. Calling it with an empty string just writes out a line break.



  • Advertisement
  • Registered Users Posts: 640 ✭✭✭Kernel32


    str8_away wrote:
    Intresting fact but take a look on these two web sites http://www.4guysfromrolla.com/webtech/043099-1.shtml and http://www.asp101.com/tips/index.asp?id=88 you will see why there are reasons to use server.createobject.
    As I said, if you use IIS4 which is on NT4 then use Server.CreateObject. Notice the reference to MTS in those articles. Thats NT4. IIS5 and IIS6 on Win2k and Win2003 use COM+ and it is not needed. Those articles are pretty dated at this point. It all comes down to context flow. On NT4 IIS and MTS were essentally two different things. Since Win2k they were merged into COM+ Services. I don't have time to search the help files to back this up but here is a posting by a Microsoft MVP..

    http://groups.google.com/group/microsoft.public.inetserver.asp.general/browse_thread/thread/aef0e074e763c2c5/409380a9492fb9c8?lnk=st&q=server.createobject+legacy&rnum=4&hl=en#409380a9492fb9c8

    The reason people keep using it is because a)they copy and paste dated examples and b)many examples are simply wrong.

    It's a small point but I figured I would raise it.


  • Registered Users Posts: 1,488 ✭✭✭mathew


    Thanks for your help but its still not working!! The error i'm getting is
    ADODB.Recordset error '800a0cc1'

    Item cannot be found in the collection corresponding to the requested name or ordinal.

    site/photos.asp, line 102

    Thanks again


  • Moderators, Politics Moderators Posts: 39,788 Mod ✭✭✭✭Seth Brundle


    your column names don't correspond to the ones referred to in the script!
    whats on 102?


  • Registered Users Posts: 1,488 ✭✭✭mathew


    they do... i just coppied the section of the script that was giving me the error so according to what you see the line isn't 102, but in reation to the whole page it is..

    Thanks for the help


  • Moderators, Politics Moderators Posts: 39,788 Mod ✭✭✭✭Seth Brundle




  • Advertisement
  • Closed Accounts Posts: 2,046 ✭✭✭democrates


    group is an sql keyword, that has to be the problem :)

    Change the column name to photogroup or some such name and your sql and vbscript code accordingly.

    Kicking myself for missing that.

    PS another debugging trick is to response.write the sql query that is failing, then slap that into say an Access query and see what results/error message it produces.


  • Registered Users Posts: 1,488 ✭✭✭mathew


    Genius, Thanks a million. I would never have fouund that myself

    Is amazing how simple it was...


  • Moderators, Politics Moderators Posts: 39,788 Mod ✭✭✭✭Seth Brundle


    well done democrates - a far too simple error that most of us didn't spot!


Advertisement