yanike
yanike

Reputation: 847

Error: Object doesn't support this property or method

I am developing with WebMatrix 2.0 RC and love it. I'm sure the database is set up correctly, but I'm getting this error:

Microsoft VBScript runtime

error '800a01b6'

Object doesn't support this property or method: 'id'

/myfile.asp, line 24

MYFILE.ASP

<%@ Language="VBScript" %>
<%
    set db = Server.Createobject("ADODB.Connection")
    db.open "Provider=Microsoft.SQLSERVER.CE.OLEDB.4.0;Data Source=" & server.mappath("/App_Data/databasefile.sdf")
%>

<%
set grs = Server.CreateObject("ADODB.recordset")
grs.Open "SELECT * FROM gells", db
do until grs.EOF
    for each x in grs.Fields
        response.write("<table style='margin-bottom:8px;'><tr><td style='vertical-align:top; padding-top:4px;'><img src='gells/uploads/gelthumbs/" & x.id & "_gelthumb.jpg' style='border:1px solid #FFFFFF;' /></td><td style='vertical-align:top; padding-left:4px; text-align:justify;'><strong>" & x.title & "</strong><br />" & x.info & "</td></tr><tr><td colspan='2' style='text-align:right; padding-top:4px;'><a href='gells.php?gelsid=" & x.id & "' ><img src='gells/viewgell.png' style='border:none;' /></a></td></tr></table>")
    next
    grs.MoveNext
loop
grs.close
%>

Upvotes: 1

Views: 6258

Answers (1)

AnthonyWJones
AnthonyWJones

Reputation: 189535

The x variable in your code will be a Field object. A field object does not have an id property hence the error. I suspect that id, title and info are actually the names of the fields you want to use. Hence your code should look like this:

grs.Open "SELECT id, title, info FROM gells", db  
do until grs.EOF  
    response.write "<table style='margin-bottom:8px;'><tr><td style='vertical-align:top; padding-top:4px;'><img src='gells/uploads/gelthumbs/" _
        & Server.URLEncode(grs("id")) _
        & "_gelthumb.jpg' style='border:1px solid #FFFFFF;' /></td><td style='vertical-align:top; padding-left:4px; text-align:justify;'><strong>" _
        & Server.HTMLEncode(grs("title")) _
        & "</strong><br />" & Server.HTMLEncode(grs("info")) _
        & "</td></tr><tr><td colspan='2' style='text-align:right; padding-top:4px;'><a href='gells.php?gelsid=" _
        & Server.URLEncode(grs("id")) _
        & "' ><img src='gells/viewgell.png' style='border:none;' /></a></td></tr></table>"
    grs.MoveNext  
loop  
grs.close

Note the SQL only includes the fields you need, also never send unencoded data directly from the DB.

Upvotes: 3

Related Questions