Hi I have written a class to run a stored procedure. When the class is instantiated I want to pass paramaters in the constructor. This works fine in VB.NET however when I move this to ASP.net into a code behind file I get the error message:
BC30455: Argument not specified for parameter 'StrConn' of 'Public Sub New(StrConn As String, StrSp As String)'.
I think this has something to do with the fact that when you use code behind the class has to inherit 'page' and when it is created the inherited constructor is called instead of the paramater one.
Heres the class code:
Public Class spNoParam
Inherits Page
Private objConn As SqlConnection
Private cmdSp As SqlCommand
Private m_strConn As String
Private m_strSp As String
Sub New(ByVal StrConn As String, ByVal StrSp As String)
m_strConn = StrConn
m_strSp = StrSp
objConn = New SqlConnection(StrConn)
cmdSp = New SqlCommand(StrSp, objConn)
cmdSp.CommandType = CommandType.StoredProcedure
End Sub
Sub runSp()
objConn.Open()
cmdSp.ExecuteNonQuery()
objConn.Close()
End Sub
End Class
And this creates it:
'strConn and strSp are defined above
Dim myClass2 As New spNoParam(strConn, strSp)
Any ideas?
Thanks
Alex




Reply With Quote