我不知道为什么我在自定义类
中收到此错误重载解析失败,因为第15行和第16行没有“项目”可访问。要查看代码,请点击链接
Imports System.Configuration
Public Class AppSettings
Private config As Configuration
Public Sub AppSetting()
config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
End Sub
Public Function GetConnectionString(ByVal key As String) As String
Return config.ConnectionStrings.ConnectionStrings(key).ConnectionString
End Function
Public Sub SaveConnectionString(ByVal key As String, ByVal value As String)
config.ConnectionStrings(key).ConnectionString = value
config.ConnectionStrings(key).ProviderName = "MySql.Data.MySqlClient"
config.Save(configurationSaveMode.Modified)
End Sub
End Class
答案 0 :(得分:0)
您在.ConnectionStrings
方法中正确使用的config
和.ConnectionStrings(key)
之间缺少GetConnectionString
:
config.ConnectionStrings.ConnectionStrings(key).ConnectionString = value
config.ConnectionStrings.ConnectionStrings(key).ProviderName = "MySql.Data.MySqlClient"
但你可以使用临时变量来简化
Dim connString = config.ConnectionStrings.ConnectionStrings(key)
connString.ConnectionString = value
connString.ProviderName = "MySql.Data.MySqlClient"
或使用With
声明
With config.ConnectionStrings.ConnectionStrings(key)
.ConnectionString = value
.ProviderName = "MySql.Data.MySqlClient"
End With