http://blog.csdn.net/lizanhong/archive/2004/06/23/24374.aspx希望对你有用。

解决方案 »

  1.   

    private XmlDocument configData=new XmlDocument();
    private string appPath = Application.ExecutablePath+".config";/// <summary>
    /// 获取节点值
    /// </summary>
    /// <param name="key"></param>
    /// <returns></returns>
    private string GetAppValue(string key)
    {
    return configData.SelectSingleNode("/configuration/appSettings/add[@key='"+key+"']").Attributes["value"].Value;
    }
    /// <summary>
    /// 设置节点值
    /// </summary>
    /// <param name="key"></param>
    /// <param name="newValue"></param>
    private void SetAppValue(string key,string newValue)
    {
    configData.SelectSingleNode("/configuration/appSettings/add[@key='"+key+"']").Attributes["value"].Value = newValue;
    configData.Save(appPath);
    }private void Init()
    {
    configData.Load(appPath);
    }
      

  2.   

    TO 楼上各位大虾:   现在俺的想法是把KEY和value的值弄成dataset+dataGrid的方式,然后再进行添加删改。不过挂dataGrid时遇到麻烦,希望各位大虾指点迷津。分不够可再加。
      

  3.   

    给你一个例子:更改Web.config中的ConfigurationSetting
    public  static  bool  appSettingsEdit(string  WebConfigDirectory,string  appSettingsAddkey,string  keyvalue)  
    {  
       try  
       {  
    string  path=WebConfigDirectory+"\\web.config";  
    XmlDocument  xd=new  XmlDocument();  
    xd.Load(path);  
    //如果没有appSetting,则添加  
    if(xd.SelectNodes("//appSettings").Count==0)  
    {  
    xd.DocumentElement.AppendChild(xd.CreateElement("appSettings"));  
    }  
    //判断节点是否存在,如果存在则修改当前节点  
    bool  addNode=true;  
    foreach(XmlNode  xn1  in  xd.SelectNodes("/configuration/appSettings/add"))  
    {  
    if(xn1.Attributes["key"].Value==appSettingsAddkey)  
    {  
    addNode=false;  
    xn1.Attributes["value"].Value=keyvalue;  
    //xn1.ParentNode.RemoveChild(xn1);  
    break;  
    }  
    }  
    if(addNode)  
      {  
      //创建新节点  
    XmlNode  xn2=xd.CreateElement("add");  
    //添加key  
    XmlAttribute  xa=xd.CreateAttribute("key");  
    xa.Value=appSettingsAddkey;  
    xn2.Attributes.Append(xa);  
    //添加value  
    xa=xd.CreateAttribute("value");  
    xa.Value=keyvalue;  
    xn2.Attributes.Append(xa);  
    xd.SelectSingleNode("/configuration/appSettings").AppendChild(xn2);  
    }  
    //保存web.config  
    xd.Save(path);  
    return  true;  
        }  
        catch  
        {  
    return  false;  
        }  
    }
      

  4.   

    CSDN和MSDN上都有例子,楼主不妨看一下.
      

  5.   

    http://cn.thespoke.net/MyBlog/xrascal/MyBlog.aspx
      

  6.   

    现在的主要问题是如何通过dataset挂到dataGrid上,并进行增、删、改。希望高手们来指点指点。