I’m doing a lab for school, and I came across something I have never done before: create a default constructor within my class. It involves creating a private field to store the connection string, and then create a default constructor that sets the connection string.
Here is what I have so far:
Public Class Appointments
Private sqlconnection As String = ConfigurationSettings.AppSettings("ConnectionString")
Private Property connectionstring() As String
Get
Return sqlconnection
End Get
Set(ByVal value As String)
End Set
End Property
Public Sub New(ByVal sConnectionString As String)
sqlconnection = sConnectionString
End Sub
Am I doing this right? What is going on?
Looks good to me but you’ve already initilized the connection string as a private variable up top.
Are you supposed to allow someone to pass in a connection string?
Your set may need to be:
You also need a parameterless constructor, something which gives the string a value when you instantiate an object.
For instance the parameterless constructor could be set by a web / app config file:
The whole thing could be: