P
Przemek
Hi,
I'm creating small aspnet application. The main purpose of application
is to manage list of contracts (adding, updating, deleting) and
creating reports based on database of contracts. So I've created a
class Contract, which have all contract's properties and method like
InsertContract etc. In my InsertContract method I want to pass Contract
object to my database provider class Insert method. I'm receiving an
error "Reference to a non-shared member requires an object reference".
It's understandable, because I didn't instantiate database provider
object before. I can workaround this error using "shared" keyword in my
database provider method definition. My question is, if it's correct
solution and if not, what shall I do. Here is my code:
Public Class Contract
Public Property Trademark() As String
Get
Return _trademark
End Get
Set(ByVal value As String)
_trademark = value
End Set
End Property
' other properties
Public Sub New()
End Sub
'other methods
Public Sub InsertContract ()
DatabaseProvider.InsertContract (contract)
End Sub
End Class
Public Class DatabaseProvider
Public Shared Sub InsertContract (record as Contract)
'adding contract to database
End Class
Przemek
I'm creating small aspnet application. The main purpose of application
is to manage list of contracts (adding, updating, deleting) and
creating reports based on database of contracts. So I've created a
class Contract, which have all contract's properties and method like
InsertContract etc. In my InsertContract method I want to pass Contract
object to my database provider class Insert method. I'm receiving an
error "Reference to a non-shared member requires an object reference".
It's understandable, because I didn't instantiate database provider
object before. I can workaround this error using "shared" keyword in my
database provider method definition. My question is, if it's correct
solution and if not, what shall I do. Here is my code:
Public Class Contract
Public Property Trademark() As String
Get
Return _trademark
End Get
Set(ByVal value As String)
_trademark = value
End Set
End Property
' other properties
Public Sub New()
End Sub
'other methods
Public Sub InsertContract ()
DatabaseProvider.InsertContract (contract)
End Sub
End Class
Public Class DatabaseProvider
Public Shared Sub InsertContract (record as Contract)
'adding contract to database
End Class
Przemek