Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
HTML
<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 :-
VB
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)

VB
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
Updated 20-Sep-11 3: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

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

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

</serverinfos>
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900