<?xml version="1.0" encoding="utf-8" ?> <configuration> <connectionStrings> <add name="sqlserver" connectionString="Data Source=WT01395sqlexpress;Initial Catalog=mydb;Integrated Security=True"/> </connectionStrings> <appSettings> <add key=""/> </appSettings> </configuration>
引入Configuration的 References库
读取
string conStr = ConfigurationManager.ConnectionStrings["sqlserver"].ToString();
用于保存数据
写入
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.AppSettings.Settings.Remove("lastLoginUser"); config.AppSettings.Settings.Add("lastLoginUser", userName); config.Save();
只会把值写入到OesShareUI.exe.Config 不会写在 源文件上