我有一个带有此代码的App.config
<appSettings>
<add key="dataPath" value="" />
<add key="databaseConnectionString" value="MultipleActiveResultSets=True;SERVER=;DATABASE=;UID=;PWD=" />
<add key="APIaddress" value="" />
<add key="Timer" value="1" />
<add key="BufferSize" value="100" />
<add key="fisrtConfig" value="1" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
我可以使用此代码访问这些值
Srv = System.Configuration.ConfigurationManager.AppSettings("APIaddress").ToString()
timer = CInt(System.Configuration.ConfigurationManager.AppSettings("TimerEsecuzione").ToString())
connectionString = System.Configuration.ConfigurationManager.AppSettings("databaseConnectionString").ToString()
BufferSize = System.Configuration.ConfigurationManager.AppSettings("BufferSize").ToString()
isFirstConfig = IIf(System.Configuration.ConfigurationManager.AppSettings("fisrtConfig").ToString() = 1, True, False)
在我的代码运行期间,我会更新其中一个。我尝试了不同类型的代码,但没有人可以更新它。这些是我试过的代码:
第一
Dim configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
Dim settings = configFile.AppSettings.Settings
settings("fisrtConfig").Value = 0
configFile.Save(ConfigurationSaveMode.Modified)
ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name)
第二
ConfigurationManager.AppSettings.Item("fisrtConfig") = 0
你能帮我吗?