簡體   English   中英

VBScript中。 數據集返回時出錯

[英]VBScript. Error on data set return

我沒有使用VBScript編程的經驗,我想使用一些OOP方法。 如果您查看下面的代碼,您將看到我正在嘗試使用一組返回數據集的方法創建數據庫訪問類。 不知道為什么,但收到錯誤:

Microsoft VBScript runtime error '800a01c2'

Wrong number of arguments or invalid property assignment

/TrashCan/library/BLL/CreditBLLClass.asp, line 18 

我有一個.asp頁面:

<body>
    <!-- #INCLUDE FILE="library\BLL\CreditBLLClass.asp" -->
    <%             
        Dim creditBLL
        Dim reader
        creditBLL = new CreditBLLClass

            reader = creditBLL.GetData() 
            If reader.EOF = False Then
                Do While reader.EOF = False
                    Response.Write(reader.Fields("a").Value)
                    reader.MoveNext
                Loop    
            End If
    %>
</body>

CreditBLLClass.asp:

<!-- #INCLUDE FILE="DatabaseConnectionClass.asp" -->
<%
Class CreditBLLClass
    'Private variables
    Dim connection

    Public Default Function Init()
        Set Init = Me
      End Function

    Public Function GetData ()
        connection = new DatabaseConnectionClass
        GetData = connection.DBGetRecords("select a from b")
    End Function
End Class

%>

和數據庫連接類

<% 

Class DatabaseConnectionClass

'Private variables
dim pConnection

Public Default Function Init()

    Set Init = Me
  End Function

Public Function DBGetRecords ( sSQL )

    Set pConnection = Server.CreateObject( "ADODB.Connection" )
    With pConnection
            .ConnectionString = "string"
            .Open
         End With
        DBGetRecords = pConnection.Execute ( sSQL )
End Function

End Class

%>

請告訴我,我做錯了什么? 也許有一種如何構建數據訪問層的通用方法?

錯誤發生在錯誤的invalid property assignment部分。

從您的代碼:

connection = new DatabaseConnectionClass
GetData = connection.DBGetRecords("select a from b")

使用對象時必須使用Set

把它改成這個:

Set connection = new DatabaseConnectionClass
Set GetData = connection.DBGetRecords("select a from b")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM