Click here to Skip to main content
12,633,990 members (24,569 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
Hello friends I trying to save and retrieve data in xml file using vb.net first of all I add a xml file (emp.xml) from add new item -> add some dummy data into it like
<serverinfo>
  <servername>abc</servername>
  <serverpwd>123</serverpwd>
</serverinfo>


copy the file from application folder to debug folder and write the following code on for save data :-
Dim path As String = Application.StartupPath & "\emp.xml"
    Dim dt As New DataTable("emp")
    Dim ds As New DataSet()
    ds.ReadXml(path)
    dt.Columns.Add(New DataColumn("eid", Type.[GetType]("System.Int32")))
    dt.Columns.Add(New DataColumn("ename"))
    Dim r As DataRow = ds.Tables(0).NewRow()
    r(0) = TextBox1.Text
    r(1) = TextBox2.Text
    ds.Tables(0).Rows.Add(r)
    ds.WriteXml(path)


and for display data into datagridview named (dg_Data)

Dim path As String = Application.StartupPath & "\emp.xml"
Dim ds As New DataSet()
ds.ReadXml(path)
dg_Data.DataSource = ds.Tables(0)


But it give some error when it read the xml file the error is "Root element is missing" so please help me..

Thanks in advance
Parveen Rathi
Posted 20-Sep-11 2:27am
Updated 20-Sep-11 4:16am
v2
Comments
Parveen Rathi 22-Sep-11 1:00am
   
Thanks sir my problem has been solved but I want to delete a particular record from the xml file so give some suggestion if any

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Add a root to your XML like this :
<serverinfos>

<serverinfo>
  <servername>abc</servername>
  <serverpwd>123</serverpwd>
</serverinfo>

</serverinfos>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 20 Sep 2011
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100