错误:对象不支持此属性或方法

时间:2023-01-21 19:20:06

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:

我正在使用WebMatrix 2.0 RC开发并喜欢它。我确定数据库设置正确,但我收到此错误:

Microsoft VBScript runtime

Microsoft VBScript运行时

error '800a01b6'

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

Object不支持此属性或方法:'id'

/myfile.asp, line 24

/myfile.asp,第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
%>

1 个解决方案

#1


3  

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:

代码中的x变量将是Field对象。字段对象没有id属性,因此出错。我怀疑id,title和info实际上是你想要使用的字段的名称。因此,您的代码应如下所示:

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.

请注意,SQL仅包含您需要的字段,也不会直接从数据库发送未编码的数据。

#1


3  

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:

代码中的x变量将是Field对象。字段对象没有id属性,因此出错。我怀疑id,title和info实际上是你想要使用的字段的名称。因此,您的代码应如下所示:

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.

请注意,SQL仅包含您需要的字段,也不会直接从数据库发送未编码的数据。