<appSettings>
<add key="ConnectionString" value="Data Source=192.168.1.101; Initial Catalog=data; uid=sa; pwd=123"/>
</appSettings>
就是像上面那个连接的ip 数据库名 用户 和密码 怎么根据条件动态修改呀!  在此先谢谢各位了!注:这个IP地址不是固定的 ,如果能另写一个类,调用webconfig参数更好了,期待中……

解决方案 »

  1.   

    http://zhidao.baidu.com/question/81417614
    或者多谢几个
    <add key=.....>
      

  2.   

    或者多添加几个
    public void SaveConfig(string key, string value)
        {
            try
            {
                string fileName = "Web.Config";
                XmlDocument document = new XmlDocument();
                document.Load(fileName);
                ((XmlElement)document.SelectSingleNode(@"//AppSetting/add[@key='" + key + "']")).SetAttribute("Value", value);
                document.Save(fileName);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
      

  3.   

    除了操作xml的方式,ms还有内置方法的正规军
    Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/");
    //清除并重新写入appSettings
    config.AppSettings.Settings.Clear();
    config.AppSettings.Settings.Add("keyname", "c%o@f#f@e(e%f^o*x");