vb.net write data to xml file

I am trying to write a vb.net program for a smart device, that writes the input from txt/combo boxes to an xml file. This file will be stored in the '/my documents/ data.txt' dir.  I plan to use active sync to push the data to the pc.  Here is what I have piced together so far,  the program creates the file, however does not populate with data.  I need to know what I should do next.

Dim t As New System.Data.DataTable
        With t.Columns
            .Add("eqnumber")
            .Add("OpStatus")
            .Add("keys")
            .Add("lights")
            .Add("glass")
        End With
        Dim r As System.Data.DataRow = t.NewRow
        r.Item("eqnumber") = Eq_Num.Text
        r.Item("opstatus") = ComboBox1.Text
        r.Item("keys") = ComboBox2.Text
        r.Item("lights") = ComboBox3.Text
        r.Item("glass") = ComboBox4.Text

        Dim ds As New System.Data.DataSet
        ds.tables.add(t)
        ds.writexml("\my documents\data.xml")

maximjonAsked:
Who is Participating?
 
toddhdConnect With a Mentor Commented:
For what it is worth, the way you are going about it is a little strange. I assume you were looking an easy "writetoxml" statement, but this is likely *not* the way to go about it.

Instead, create a class to handle your data.

Class MyClass
Private _eqnumber as Integer
Private _OpStatus as Boolean
..
..
Public Property EQNumber() As Integer
' Get/Set go here
End Property
..
..
End MyClass

Assign your values to the class:
Dim objMyClass as New MyClass
objMyClass .EQNumber = Eq_Num.Text
..
..

Then serialize the whole thing like this:

'========XML Serialization=========
Sub XMLSerialize(ByVal mc As MyClass)
  Dim wri As New StreamWriter("c:\MyClass.xml")
  Try
    Dim ser As New XmlSerializer(GetType(MyClass))
    ser.Serialize(wri, mc)
  Catch ex As Exception
    MsgBox(ex.ToString)
  Finally
    wri.Close()
  End Try
End Sub
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.