• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

Adding a record to the dataset and passing it to the XML file - ADO.NET

When i fill in the form and click on btnAdd it should add that record to a XML file. BUT IT DOESN'T DO SO. When i opened the xml file all i can see is : <?xml version="1.0" standalone="yes" ?>
  <NewDataSet />

The code is given below.

Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
        ' creating a DataSet
        Dim ds As DataSet = New DataSet

        'Creating an empty DataTable
        Dim dtCus As New DataTable("Customers")

        'Creating  8 data columns
        Dim dcolCus_fname As New DataColumn("Cus_fname")
        dcolCus_fname.DataType = GetType(String)
        Dim dcolCus_lname As New DataColumn("Cus_lname")
        dcolCus_lname.DataType = GetType(String)
        Dim dcolTel As New DataColumn("Tel")
        dcolTel.DataType = GetType(String)
        Dim dcolAdd_line1 As New DataColumn("Add_Line1")
        dcolAdd_line1.DataType = GetType(String)
        Dim dcolAdd_line2 As New DataColumn("Add_Line2")
        dcolAdd_line2.DataType = GetType(String)
        Dim dcolpost_code As New DataColumn("Post_Code")
        dcolpost_code.DataType = GetType(String)
        Dim dcolday_read As New DataColumn("Day_Read")
        dcolday_read.DataType = GetType(String)
        Dim dcolnight_read As New DataColumn("Night_Read")
        dcolnight_read.DataType = GetType(String)

        'Adding the columns to the DataTable
        dtCus.Columns.Add("Cus_fname")
        dtCus.Columns.Add("Cus_lname")
        dtCus.Columns.Add("Tel")
        dtCus.Columns.Add("Add_Line1")
        dtCus.Columns.Add("Add_Line2")
        dtCus.Columns.Add("Post_Code")
        dtCus.Columns.Add("Day_Read")
        dtCus.Columns.Add("Night_Read")

        'Adding rows to the DataTable
        Dim row As DataRow
        row = dtCus.NewRow()

        row("Cus_fname") = txtCustomerFirstName.Text
        row("Cus_lname") = txtCustomerLastName.Text
        row("Tel") = txtTelNo.Text
        row("Add_Line1") = txtAddressLine1.Text
        row("Add_Line2") = txtAddressLine2.Text
        row("Post_Code") = txtPostcode.Text
        row("Day_Read") = txtDayRead.Text
        row("Night_Read") = txtNightRead.Text
        dtCus.Rows.Add(row)

        ds.WriteXml("Customers.xml")

What is the problem?
0
sergeiweerasuriya
Asked:
sergeiweerasuriya
  • 2
1 Solution
 
nayernaguibCommented:
You did not add the DataTable to the DataSet. :-)

_______________

  Nayer Naguib
0
 
sergeiweerasuriyaAuthor Commented:
what is the code to do that and where should i write it?
0
 
sergeiweerasuriyaAuthor Commented:
oh yes i added ds.Tables.Add(dtCus) and now it's working. thanks.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now