?
Solved

vb.net write data to xml file

Posted on 2005-04-28
1
Medium Priority
?
323 Views
Last Modified: 2010-04-23
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")

0
Comment
Question by:maximjon
1 Comment
 
LVL 8

Accepted Solution

by:
toddhd earned 375 total points
ID: 13888820
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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month13 days, 8 hours left to enroll

750 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