我创建了一个登录表单,用户名和密码等登录详细信息存储在xml数据库中。
现在,当特定用户想要更改他/她的密码时。如何在C#中使用xml数据库。我对xml数据库没什么了解。请尽早帮我。
更改密码表单如下所示
User name :
Old password:
new password:
Confirm password:
Change(button)
当用户提供必要信息并单击更改按钮时。存储在xml数据库中的旧密码应该被新密码替换。
答案 0 :(得分:0)
请参阅how to change xml value file using c#
和How To Modify and Save XML with the XmlDocument Class in the .NET Framework
答案 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);
}