2012-04-19 10 views
1

VBScriptでプログラミング経験がありません。OOPアプローチを使用したいと思います。以下のコードを見てみると、データセットを返す一連のメソッドでDBアクセスクラスを作成しようとしていることがわかります。VBScript。データセットのエラーが返されました

<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 

%> 

Microsoft VBScript runtime error '800a01c2' 

Wrong number of arguments or invalid property assignment 

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

私は.aspページを持っている:なぜ、しかし、受信エラー見当がつかない

Ple私が間違っていることを教えてください。たぶん、データアクセス層を構築する方法の共通のアプローチがありますか?

+0

? – AnthonyWJones

+0

デフォルトコンストラクタ.. – Sergejs

+1

VBScriptはOOPスタイルのプログラミング用に作成されていないことに注意してください。クラスでコードを整理することは可能ですが、悪い習慣ではありませんが、VOPcriptにOOPをあまりにも強要しないでください。後で問題やパフォーマンスの問題にぶつかるでしょう。 –

答えて

4

エラーは、エラーのinvalid property assignment部分にあります。あなたのコードから

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

あなたがオブジェクトを使用するときSetを使用する必要があります。

これに変更し、それは:これら `Init`方法は何をしている

Set connection = new DatabaseConnectionClass 
Set GetData = connection.DBGetRecords("select a from b") 
関連する問題