如此配置
<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <appSettings>
<add key="Center" value="database=Center;server=01;uid=sa;pwd="";Max pool size =299;enlist=true;persist security info=true" />
</appSettings>
</configuration>

解决方案 »

  1.   

    读出:string con=System.Configuration.ConfigurationSettings.AppSettings["Center"];更改:
    XmlDocument doc = new XmlDocument();
    doc.Load("yysms.exe.config");
    XmlNode node = doc.DocumentElement.SelectSingleNode("appSettings");
    node.SelectSingleNode("descendant::add[@key=Center]").Attributes[1].Value = ty;
    doc.DocumentElement.SelectSingleNode("appSettings").InnerXml = node.InnerXml;
    doc.Save("yysms.exe.config");
      

  2.   

    数据库连接串保存到xml文件中,然后参数的修改反映到xml文件中,
    数据库联接的时候从xml文件中提取必要参数,
    操作xml文件需要引用System.Xml;
      

  3.   

    我有多个<add key = .../>
    那我该怎么读取其中的一个呢?
      

  4.   

    /// <summary>
    /// 修改配置文件(数据库连接字符串)
    /// </summary>
    /// <param name="connString"></param>
    private void UpdateConfig( string databaseName )
    {
    Assembly Asm = Assembly.GetExecutingAssembly(); 
    string fullPath = "";
    fullPath = Asm.Location.Substring(0, (Asm.Location.LastIndexOf("\\") + 1) ) + "MakeAllowanceSheet.exe.config";
    XmlDocument xmlDoc=new XmlDocument();
    xmlDoc.Load(fullPath); XmlNodeList nodeList=xmlDoc.SelectSingleNode("/configuration/appSettings").ChildNodes;
    foreach(XmlNode xn in nodeList)//遍历所有子节点
    {
    XmlElement xe=(XmlElement)xn; if( xe.GetAttribute("key").IndexOf("BC.MTARR.ConnectionString") != -1 )
    {
    xe.SetAttribute("value","server=" + databaseName + ";database=MTSIM;Connection Reset=FALSE;");
    }
    if( xe.GetAttribute("key").IndexOf("BC.MTARR.Server") != -1 )
    {
    xe.SetAttribute("value",databaseName );
    }
    }
    xmlDoc.Save(fullPath);
    }
      

  5.   

    使用ConfigurationSettings类更方便
      

  6.   

    http://community.csdn.net/Expert/TopicView.asp?id=3344847
      

  7.   

    最简单的是这样:
    app.config:<?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <appSettings>
    <add key="strUserName" value="ggggg" />
    <add key="strPassWord" value="yyyyy" />
    </appSettings></configuration>
    cs里面:using System.Configuration;strUserName=ConfigurationSettings.AppSettings["strUserName"];
    strPassWord=ConfigurationSettings.AppSettings["strPassWord"];