Oop VBScript。返回数据集时出错
我没有任何使用VBScript编程的经验,我想使用一些面向对象的方法。如果您查看下面的代码,您将看到我正在尝试使用一组返回数据集的方法创建DB access类。不知道原因,但接收错误:Oop VBScript。返回数据集时出错,oop,asp-classic,vbscript,data-access-layer,Oop,Asp Classic,Vbscript,Data Access Layer,我没有任何使用VBScript编程的经验,我想使用一些面向对象的方法。如果您查看下面的代码,您将看到我正在尝试使用一组返回数据集的方法创建DB access类。不知道原因,但接收错误: Microsoft VBScript runtime error '800a01c2' Wrong number of arguments or invalid property assignment /TrashCan/library/BLL/CreditBLLClass.asp, line 18 我有
Microsoft VBScript runtime error '800a01c2'
Wrong number of arguments or invalid property assignment
/TrashCan/library/BLL/CreditBLLClass.asp, line 18
我有一个.asp页面:
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
%>
请告诉我我做错了什么?也许有一种常见的方法可以构建数据访问层?错误在错误的无效属性分配部分
从您的代码:
connection = new DatabaseConnectionClass
GetData = connection.DBGetRecords("select a from b")
使用对象时必须使用“设置”
将其更改为:
Set connection = new DatabaseConnectionClass
Set GetData = connection.DBGetRecords("select a from b")
错误位于错误的无效属性分配部分
从您的代码:
connection = new DatabaseConnectionClass
GetData = connection.DBGetRecords("select a from b")
使用对象时必须使用“设置”
将其更改为:
Set connection = new DatabaseConnectionClass
Set GetData = connection.DBGetRecords("select a from b")
那些Init方法在做什么?记住VBScript不是为OOP风格的编程而设计的。虽然在类中组织代码是可能的,并且不是一种坏的做法,但不要在VBScript上强制执行OOP太多。稍后您将遇到问题/性能问题。您可以看出您是对的。。。但是,在将网站迁移到APS.NET之前,必须以某种方式重构代码,否则将花费很长时间…这些Init方法在做什么?请记住,VBScript不是为OOP风格的编程而设计的。虽然在类中组织代码是可能的,并且不是一种坏的做法,但不要在VBScript上强制执行OOP太多。稍后您将遇到问题/性能问题。您可以看出您是对的。。。但在将网站迁移到APS.NET之前,必须以某种方式重构代码,否则将花费很长时间。。。