Duane

Duane

  • NA
  • 77
  • 0

Xml issues with repeating

Nov 3 2011 10:44 AM
I need help with an Xml issue. I can't get my routine to work repeatedly. In other words, the Sub shown below can only be used once. Then I have to exit from the app so the xml file can be "reloaded" (?). Only then can I create another entry. What is wrong with my programming? I'm sure there are many minor issues, but I would prefer to concentrate on the ones that directly affect this problem. However, any help is appreciated.
[CODE]
Imports System.Xml
Public Class Form1
 Private fn As String = My.Application.Info.DirectoryPath & "\Entry.xml"
 Dim doc As New XmlDocument
 Private Sub Form1_Load(ByVal sender As Object, ByVal e As  System.EventArgs) Handles Me.Load
 doc.Load(fn)
 End Sub
 Private Sub Button1_Click(ByVal sender As Object, ByVal e As  System.EventArgs) Handles Button1.Click
 Dim _Name As String = InputBox("Name?")
 Dim _Score As String = InputBox("Score?")
 Dim _Date As String = InputBox("Date?")
 Dim HSE As XmlElement = doc.CreateElement("HSE")
 Dim nameElem As XmlElement = doc.CreateElement("Name")
 nameElem.InnerText = _Name
 Dim scoreElem As XmlElement = doc.CreateElement("Score")
 scoreElem.InnerText = _Score
 Dim dateElem As XmlElement = doc.CreateElement("Date")
 dateElem.InnerText = _Date
 HSE.AppendChild(nameElem)
 HSE.AppendChild(scoreElem)
 HSE.AppendChild(dateElem)
 doc.DocumentElement.AppendChild(HSE)
 doc.Save(fn)
 doc = Nothing
 Dim xmlFile As XmlReader
 xmlFile = XmlReader.Create(fn, New XmlReaderSettings)
 Dim ds As New DataSet
 ds.ReadXml(xmlFile)
 DGV.DataSource = ds.Tables(0)
 End Sub
End Class
[/CODE]


Answers (1)