使用C#更新xml数据库

时间:2011-10-19 06:34:51

标签: c#

我创建了一个登录表单,用户名和密码等登录详细信息存储在xml数据库中。

现在,当特定用户想要更改他/她的密码时。如何在C#中使用xml数据库。我对xml数据库没什么了解。请尽早帮我。

更改密码表单如下所示

User name : 
Old password:
new password:
Confirm password:

Change(button)

当用户提供必要信息并单击更改按钮时。存储在xml数据库中的旧密码应该被新密码替换。

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

private void btnLogIn_Click(object sender, EventArgs e)
    {
        if (checkBox_Remember.Checked)
                {
                    UpdateAppSettings_("Remember", "1");
                    UpdateAppSettings_("UserName", User.UserName);
                    UpdateAppSettings_("Password", password);
                }
    }
private void UpdateAppSettings_(string KeyName, string KeyValue)
    {
        XmlDocument XmlDoc = new XmlDocument();
        XmlDoc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
        foreach (XmlElement xElement in XmlDoc.DocumentElement)
        {
            if (xElement.Name == "appSettings")
            {
                foreach (XmlNode xNode in xElement.ChildNodes)
                {
                    if (xNode.Attributes[0].Value == KeyName)
                    {
                        xNode.Attributes[1].Value = KeyValue;
                    }
                }
            }
        }
        XmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
    }