I'm disapppointed. I would've thought that a self-appointed genius would be able to figure this out in his sleep!
I can think of two possible solutions here. One is to create your enum:
Code:
Private Enum ProviderTypes
MicrosoftJetOLEDB40
SQLOLEDB
MSDAORA
End Enum
And when you want to use it as a string value all you have to do is invoke ToString on it:
Code:
Dim sTest As String
sTest = ProviderTypes.MicrosoftJetOLEDB40.ToString()
MessageBox.Show(sTest)
The problem with this approach is that if you actually wanted to use the Enum values as part of a connection string or something they wouldn't be entirely correct, since you have to drop the punction out of ones like "Microsoft.Jet.OLEDB.4.0" because you simply can't have periods in variable/object names.
If you wanted to have the nice intellisense popup provided by using an enum as a property - and you wanted the true values of the enum constants, you could add in a little function that did some converting for you, for ex:
Code:
Private Function GetProviderTypeAsString(eProviderType As ProviderTypes) As String
Select Case eProviderType
Case ProviderTypes.MicrosoftJetOLEDB40
Return "Microsoft.Jet.OLEDB.4.0"
Case Else ' Return ToString version of provider types that don't need converting.
Return eProviderType.ToString()
End Select
End Function
The function above would return a more useful string for use with connection strings or whatever.
Simple usage (and a great way to verify/test that it works):
Code:
' This displays "Microsoft.Jet.OLEDB.4.0"
MessageBox.Show(GetProviderTypeAsString(ProviderTypes.MicrosoftJetOLEDB40))
' This displays "SQLOLEDB"
MessageBox.Show(GetProviderTypeAsString(ProviderTypes.SQLOLEDB))
You'd show the property to the consumer of your class as the enum - for easy setting and displaying with intellisense. When it came time to actually do something with that property, like use it in a connection string, you'd use the conversion function to get the proper value for it.
Paul