1

我对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>

我已经对这个主题进行了相当多的研究,但还没有找到解决问题的方法。任何帮助将不胜感激

4

1 回答 1

1

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

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

Next 正确修复列名。

于 2013-05-31T18:09:23.800 回答