程序运行时如何修改app.exe.config配置文件的值?

billow_chentao 2010-03-28 03:27:46
在config文件里保存了数据库连接信息。这些信息的修改只能在程序退出时用记事本打开编辑吗?如何实现在程序里用户配置数据连接信息后,保存到config里,程序用新的连接信息来运行。
...全文
194 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2010-03-28
  • 打赏
  • 举报
回复
Configuration C=ConfigurationManager.OpenExeConfiguration(String .Empty);
C.AppSettings.Settings["Server"].Value = "";
C.AppSettings.Settings["Database"].Value = "TEST";
C.AppSettings.Settings["Uid"].Value = "sa";
C.AppSettings.Settings["Pwd"].Value = "sa";
C.Save(ConfigurationSaveMode.Modified);
public static void SetConfiguration(string key, string value,string filePath)
{
Configuration configuration = null;
AppSettingsSection appSection = null;
configuration = ConfigurationManager.OpenExeConfiguration(filePath);
appSection = configuration.AppSettings;
appSection.Settings[key].Value = value;
configuration.Save();
}
http://topic.csdn.net/u/20091027/09/83a368f5-7086-4186-8652-d08ffe46ba29.html

16,549

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧