Solved write data to xml file

Posted on 2005-04-28
Last Modified: 2010-04-23
I am trying to write a 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
        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.writexml("\my documents\data.xml")

Question by:maximjon
    1 Comment
    LVL 8

    Accepted Solution

    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")
        Dim ser As New XmlSerializer(GetType(MyClass))
        ser.Serialize(wri, mc)
      Catch ex As Exception
      End Try
    End Sub

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now