I don't have any experience programming with VBScript
and I'd like to use some OOP
approach. If you'll look at my code below, you will see that I'm trying to create DB access class with a set of methods, that returns data sets. Have no idea why, but receiving error:
Microsoft VBScript runtime error '800a01c2'
Wrong number of arguments or invalid property assignment
/TrashCan/library/BLL/CreditBLLClass.asp, line 18
I have an .asp
page:
<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
%>
And database connection 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
%>
Please tell me what am I doing wrong? Maybe there is a common approach of how to build data access layer?
The error is in the invalid property assignment
part of the error.
From your code:
connection = new DatabaseConnectionClass
GetData = connection.DBGetRecords("select a from b")
You have to use Set
when using objects.
Change it to this:
Set connection = new DatabaseConnectionClass
Set GetData = connection.DBGetRecords("select a from b")