![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
'Get the file info
Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
'Load the file info
Dim xml = XElement.Load(config.FilePath)
Dim connStrXML = (From c In xml.Descendants("connectionStrings").Elements() _
Where c.Attribute("name").Value = "appDataConnectionString").First
'Get the connection string value
Dim connStr = connStrXML.Attribute("connectionString").Value
Dim sNewConnStr As String = "Data Source=192.168.0.1;Initial Catalog=appData;Persist Security Info=True;User ID=sa;Password=***"
connStrXML.SetAttributeValue("connectionString", sNewConnStr)
'Saving config at the same place
xml.Save(config.FilePath)