how to store as xml file

dwyane123

Member
Joined
Oct 14, 2008
Messages
23
Programming Experience
Beginner
Hi.

Any one can help me in how to store simple inputs into xml file?(for vb.net) windows mobile
 
Simplest way is to put the info into a dataset and then just use the dataset.WriteXml method.
 
convert to xml using dataset

but i am assuming the imput does not have a database in the pda yet. Is it still possible to use dataset? do you have an example of the code? thanks alot
 
First let me say that a dataset is not needed for exporting to XML and will use more resources (although negligeble) then possibly needed. However it maybe easier to use this method if your not familar with coding for XML. But to answer your question, yes you can use and add data to a DataSet without connecting it to a database.

If you can send me the details of what you need to store and output, I can create examples of exporting the data to XML with and without the use of a dataset. You can send me a PM with the details if you want.
 
Hey Tom thanks alot for your help but can you tell me where do i go to send PM, i cant seem to get it. anw, i have got a different problem this time.

I have choose to write what i want into a notepad file intead of an xml using this code.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
w = New IO.StreamWriter("c:\test.txt")
For i = 0 To ListBox1.Items.Count - 1
w.WriteLine(ListBox1.Items.Item(i))
Next
w.Close()
End Sub

what can i do to create the same txtfile, however using datatables in stead of listbox..

1.I need to know how to create and store things to the datatable without the using database and then continue creating the txt document.

Can you help me with this? Thanks alot
 
Private Messages link at the top right hand of the screen under your name.

Basically the same thing but your looping through each of the dataset table records.

Again if you can provide some more specific details about the info you need to store and output I can provide approiate examples. Such as field names, how many records you will be storing etc...
 
Private Messages link at the top right hand of the screen under your name.

Basically the same thing but your looping through each of the dataset table records.

Again if you can provide some more specific details about the info you need to store and output I can provide approiate examples. Such as field names, how many records you will be storing etc...

Hey bro,

Ok what i want to do is to know how to put file into a dataset without a data adapter. For example, i will want to collect all the input and store it in a dataset/datatable. For example input = ("abc"),("cde"),("efg"). All inputs are entered using the same textbox. I would then want to put all the input into a datatable/ dataset. I will then convert all such input into a txt file format.

Hence in the txt file generated it will looks this way:

abc
cde
efg

Thanks alot for you help
 
I'll show you an example as requested but is this a single field of data you need to store? It might be much simplier to use an array if that is the case, specially considering you want to use a text file now instead of XML.

The below example creates a dataset and datatable through coding just to show you how the dataset is structured but you can create a typed dataset using the IDE dataset designer instead.

VB.NET:
[COLOR="Blue"]Public Class[/COLOR] Form1

    [COLOR="blue"]Dim [/COLOR]m_dsCustomerOrders [COLOR="blue"]As [/COLOR]DataSet = [COLOR="blue"]Nothing[/COLOR]

----------------------------------------------------------------------

   [COLOR="blue"] Private Sub [/COLOR]btnAddNewRecord_Click() [COLOR="blue"]Handles [/COLOR]btnAddNewRecord.Click

        [COLOR="blue"]Dim [/COLOR]rowInsertDataRecord [COLOR="blue"]As [/COLOR]DataRow = [COLOR="blue"]Nothing[/COLOR]

        [COLOR="teal"]'Create new data row that matches your table structure[/COLOR]
        rowInsertDataRecord = m_dsCustomerOrders.Tables("[COLOR="Red"]Orders[/COLOR]").NewRow

       [COLOR="teal"] 'Add values to columns in new datarow[/COLOR]
        rowInsertDataRecord("[COLOR="red"]OrderQuantity[/COLOR]") = [COLOR="blue"]CInt[/COLOR](TextBox1.Text.Trim)
        rowInsertDataRecord("[COLOR="red"]CompanyName[/COLOR]") = TextBox2.Text.Trim

        [COLOR="teal"]'Add new row to dataset table Orders[/COLOR]
        m_dsCustomerOrders.Tables("[COLOR="red"]Orders[/COLOR]").Rows.Add(rowInsertDataRecord)

        rowInsertDataRecord = [COLOR="blue"]Nothing[/COLOR]

    [COLOR="blue"]End Sub[/COLOR]
[COLOR="blue"][/COLOR]

---------------------------------------------------------------------

    [COLOR="blue"]Private Sub [/COLOR]Form1_Load() [COLOR="blue"]Handles MyBase[/COLOR].Load

        [COLOR="blue"]Dim [/COLOR]tblOrders [COLOR="blue"]As [/COLOR]DataTable
        [COLOR="blue"]Dim [/COLOR]colOrderId [COLOR="blue"]As [/COLOR]DataColumn

        [COLOR="teal"]'Create new dataset, declared at form level[/COLOR]
        m_dsCustomerOrders = [COLOR="blue"]New [/COLOR]DataSet("[COLOR="Red"]CustomerOrders[/COLOR]")

        [COLOR="teal"]'Create table "Orders"[/COLOR]
        tblOrders = m_dsCustomerOrders.Tables.Add("[COLOR="red"]Orders[/COLOR]")

        [COLOR="teal"]'Add three columns to Orders Table [/COLOR]
        [COLOR="blue"]With [/COLOR]tblOrders.Columns
            .Add("[COLOR="red"]OrderID[/COLOR]", Type.GetType("[COLOR="red"]System.Int32[/COLOR]"))
            .Add("[COLOR="red"]OrderQuantity[/COLOR]", Type.GetType("[COLOR="red"]System.Int32[/COLOR]"))
            .Add("[COLOR="red"]CompanyName[/COLOR]", Type.GetType("[COLOR="red"]System.String[/COLOR]"))
        [COLOR="blue"]End With[/COLOR]

        [COLOR="teal"]'Set column OrderId properties to be Primary Key and autoincrement[/COLOR]
        colOrderId = tblOrders.Columns("[COLOR="red"]OrderId[/COLOR]")
        colOrderId.AutoIncrement = [COLOR="blue"]True[/COLOR]
        colOrderId.AutoIncrementSeed = 1
        colOrderId.AutoIncrementStep = 1
        tblOrders.PrimaryKey = [COLOR="blue"]New [/COLOR]DataColumn() {colOrderId}

        [COLOR="teal"]'Just for viewing the data in a datagrid [/COLOR]
        DataGridView1.DataSource = m_dsCustomerOrders.Tables("[COLOR="red"]Orders[/COLOR]")

        [COLOR="teal"]'Clean up[/COLOR]
        colOrderId.Dispose()
        tblOrders.Dispose()

    [COLOR="blue"]End Sub[/COLOR]

[COLOR="blue"]End Class[/COLOR]
 
Thanks alot. Do you mind showing how it will be if it is an array? If its much simpler, i may wan use an array instead. Ya its single data.

Anyway, i tried the codes you gave me. However the data set and data row are underlined and it is stated that they are not defined. Is there a need to import anything to make it work?

Thanks alot
 
Last edited:
Back
Top