qq_35642853 2016-07-21 03:22 采纳率: 73.1%
浏览 1126
已采纳

用XML记住账号密码,这程序有什么问题吗

用XML记住账号密码程序如下:
string username;
string pwd;
string path = @"XMLFile1.xml";

    private void check_CheckedChanged(object sender, EventArgs e)
    {
        username = textBox1.Text;
        pwd = textBox2.Text;
        saveToXML(username, pwd);
    }


    private void saveToXML(string username, string pwd)
    {
        XmlDocument xmldoc = new XmlDocument();
        xmldoc.Load(path);
        XmlNode node;
        node = xmldoc.SelectSingleNode("XMLFile1/username");
        if (node == null)
        {
            XmlElement n = xmldoc.CreateElement("username");
            n.InnerText = username;
            xmldoc.SelectSingleNode("XMLFile1").AppendChild(n);
        }
        else
        {
            node.InnerText = username;
        }
        node = xmldoc.SelectSingleNode("XMLFile1/pwd");
        if (node == null)
        {
            XmlElement n = xmldoc.CreateElement("pwd");
            n.InnerText = pwd;
            xmldoc.SelectSingleNode("XMLFile1").AppendChild(n);
        }
        else
        {
            node.InnerText = pwd;
        }
        xmldoc.Save(path);
    }



    private void getFromXml()
    {
        XmlDocument xmldoc = new XmlDocument();
        xmldoc.Load(path);
        XmlNode node;
        node = xmldoc.SelectSingleNode("XMLFile1/username");
        username = node.InnerText;
        node = xmldoc.SelectSingleNode("XMLFile1/pwd");
        pwd = node.InnerText;
        textBox1.Text = username;
        textBox2.Text = pwd;
    }

运行后选中复选框退出后在运行依旧没有记住密码

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-07-21 03:52
    关注

    贴出你的xml文件看下。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?