Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi, ALL

 

I need a help. I have a XML file and I want to add new DataRow into XML.

 

This is my xml called test.xml

<?xml version="1.0" standalone="yes"?>
<data>
 <records>
   <row>
     <br_personid>202</br_personid>
     <br_password>pajchkildfpl</br_password>
     <br_startlevel>1</br_startlevel>
     <br_language>1</br_language>
     <br_mouse>1</br_mouse>
     
   </row>
   <row>
     <br_personid>58</br_personid>
     <br_password>phpakchmnikicpdm</br_password>
     <br_startlevel>303</br_startlevel>
     <br_language>1</br_language>
     <br_mouse>0</br_mouse>
     <br_mittelkreuz>1</br_mittelkreuz>
     <br_mode>2</br_mode>
     
   </row>
   <row>
     <br_personid>76</br_personid>
     <br_password>peegambc</br_password>
     <br_startlevel>300</br_startlevel>
     <br_language>1</br_language>
     <br_mouse>0</br_mouse>
     <br_mittelkreuz>1</br_mittelkreuz>
     <br_mode>1</br_mode>
     
   </row>
   <row>
     <br_personid>200</br_personid>
     <br_password>phpalnbb</br_password>
     <br_startlevel>0</br_startlevel>
     <br_language>1</br_language>
     <br_mouse>1</br_mouse>
     <br_mittelkreuz>1</br_mittelkreuz>
     <br_mode>0</br_mode>
     
   </row>
   </records>
</data>

 

 

This is my code to add a dataRow

 Dim mData As DataSet = New DataSet
                                               Dim mTable As DataTable = New DataTable
                                               mData.ReadXml("C:\test.xml")

                                               mTable = mData.Tables("row")

                                               Dim rows As DataRow() = mTable.Select("br_personid='58'", "br_personid")


                                               Dim NewRow As DataRow = mTable.NewRow

                                               NewRow("br_personid") = '59'
                                               NewRow("br_password") = rows(0)("br_password")
                                               NewRow("br_startlevel") = rows(0)("br_startlevel")
                                               NewRow("br_language") = rows(0)("br_language")
                                               NewRow("br_mouse") = rows(0)("br_mouse")
                                               NewRow("br_mittelkreuz") = rows(0)("br_mittelkreuz")
                                               NewRow("br_mode") = rows(0)("br_mode")
                                              

                                               mTable.Rows.Add(NewRow)
                                               mTable.AcceptChanges()
                                               mData.AcceptChanges()
                                               mData.WriteXml("C:\test1.xml")

 

 

It works but test1.xml looks strange :

<?xml version="1.0" standalone="yes"?>
<data>
 <records>
   <row>
     <br_personid>202</br_personid>
     <br_password>pajchkildfpl</br_password>
     <br_startlevel>1</br_startlevel>
     <br_language>1</br_language>
     <br_mouse>1</br_mouse>
     
   </row>
   <row>
     <br_personid>58</br_personid>
     <br_password>phpakchmnikicpdm</br_password>
     <br_startlevel>303</br_startlevel>
     <br_language>1</br_language>
     <br_mouse>0</br_mouse>
     <br_mittelkreuz>1</br_mittelkreuz>
     <br_mode>2</br_mode>
     
   </row>
   <row>
     <br_personid>76</br_personid>
     <br_password>peegambc</br_password>
     <br_startlevel>300</br_startlevel>
     <br_language>1</br_language>
     <br_mouse>0</br_mouse>
     <br_mittelkreuz>1</br_mittelkreuz>
     <br_mode>1</br_mode>
     
   </row>
   <row>
     <br_personid>200</br_personid>
     <br_password>phpalnbb</br_password>
     <br_startlevel>0</br_startlevel>
     <br_language>1</br_language>
     <br_mouse>1</br_mouse>
     <br_mittelkreuz>1</br_mittelkreuz>
     <br_mode>0</br_mode>
     
   </row>
   </records>
    <row>
     <br_personid>59</br_personid>
     <br_password>phpalnbb</br_password>
     <br_startlevel>0</br_startlevel>
     <br_language>1</br_language>
     <br_mouse>1</br_mouse>
     <br_mittelkreuz>1</br_mittelkreuz>
     <br_mode>0</br_mode>
     
   </row>
</data>

 

 

it adds new Row after [/records] tag. Please tell me how I can write in into Records

 

 

Thanks,

Erdene

Posted

Solution

 

ENdlich I have found it. The problem is there is relationship was established, During inserting a new Row I need to assign the relationship value.

 

This the example relationship fileld is "records_Id". So that I need to add new

 

newrow("relations_ID") = rows(0).("relations_ID")

 

That is all. After saving new "row" appears inside of "records" table

 

Erdenemandal

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...