I am trying to use an enumeration to limit the values an object can have. Anytime I try to assign a value using a string to the newly created object I get an casting exception error but when I use the numeric value it works fine. Can someone please help me solve this issue. The error and code are below.
Thanks
An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
Additional information: Cast from string "Access" to type 'Integer' is not valid.
Public Class DAL_Properties
Private Enum DataStoreTypes
SQLServer = 1
Access = 2
Flatfile = 3
letsgetiton = 4
End Enum
Private _databaseName As String
Private _dataSourceName As String
Private _userName As String
Private _password As String
Private _connectionString As IDbConnection
Private _command As IDbCommand
Private _datastoreType As DataStoreTypes
Public Property DatastoreType()
Get
Return _datastoreType
End Get
'*******************************************
'Error Occurs Below
'*******************************************
Set(ByVal Value)
_datastoreType = Value
End Set
End Property
End Class
Public Class DALTest
Inherits System.Windows.Forms.Form
Private Sub DALTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim babs As New DAL_Properties()
babs.DatastoreType = "Access"
MsgBox(babs.DatabaseName)
MsgBox(babs.DatastoreType.ToString)
Me.Close()
End Sub
End Class


Reply With Quote