0

Bassicly im creating a schedule where the user can input his on time such as 19/4/2012, and it gets saved into an xml file such as 19/4/2012. Im trying to perform an action that if the user enters information that has already been entered into the xml file then display a error. Im still unsure how to do such a task so any help would be appreciated thanx.

Example of xml:

<Schedule>
<Date>19/4/2012</Date>
</Schedule>

Code Example:

        private void button1_Click(object sender, EventArgs e)
      {

            XmlDocument doc = new XmlDocument();
            doc.Load("xmldoc.xml");
            XmlNode schedule = doc.CreateElement("Schedule");
            XmlNode date = doc.CreateElement("Date");
            date.InnerText = monthCalendar1.SelectionStart.ToString();
            schedule.AppendChild(date);
            doc.DocumentElement.AppendChild(schedule);
            doc.Save("xmldoc.xml");

            if(date.InnerText == monthCalander1.SelectionStart.ToString())
            {
                label6.Text = "Incorrect";

            }
        }
    }
4

1 回答 1

3

那么您需要在添加新计划之前检查日期是否存在。您可能可以执行以下操作:

if (doc.SelectSingleNode("/Schedule/Date[text()='" + monthCalander1.SelectionStart.ToString() + "']") != null){
   // already exists, do something here
}
于 2012-04-22T21:07:20.970 回答