System .__ ComObject而不是数据库值

时间:2013-05-31 18:02:34

标签: html asp-classic

我是asp的新手,我一直在尝试获取一个aspx页面来从数据库中提取数据。但是,不是显示值,而是在页面下方System.__ComObject。这是我的代码:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Form to database - showing records</title>
</head>
<body>
<% 

    Dim connection, recordset, prod, area, number
    Dim sSQL, sConnString


    prod = Request.Form("product")
    area = Request.Form("Area")
    sSQL = "SELECT * FROM [" & area & " " & prod & "]"


    connection = Server.CreateObject("ADODB.connection")
    recordset = Server.CreateObject("ADODB.Recordset")


    sConnString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
     "Data Source=" & Server.MapPath("SPC Data.mdb")

     connection.Open(sConnString)

    recordset.Open(sSQL, connection)

    'Test to see if the code will pull any number at all
    number = recordset("Batch ID").ToString
    Response.Write("Number =" & number & "<br/>")

recordset.Close
    recordset = Nothing
connection.Close
    connection = Nothing
%>
</body>
</html>

我已经研究了很多这个主题,但还没有找到解决问题的方法。任何帮助都将非常感谢

1 个答案:

答案 0 :(得分:0)

您的查询似乎返回记录集而不是单个记录,因此您应该迭代它。它应该是这样的:

For i = 0 To recordset.Fields.Count -1
 Response.Write "Field Name: " & RS.Fields(i).Name & "<br>"
 Response.Write "Field Value: " & RS(i) & "<br>"

接着 正确修复列名称。