By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,042 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,042 IT Pros & Developers. It's quick & easy.

Add row to (xml) dataset

P: n/a
Hi,

I'm having a frustrating problem :)
I have an XML like this :

<?xml version="1.0" encoding="utf-8"?>
<cgb>
<parameters>
<parameter>
<paramName>patientNr</paramName>
<paramValue>7507244765</paramValue>
</parameter>
<parameter>
<paramName>ApplicationKey</paramName>
<paramValue>cpd</paramValue>
</parameter>
</parameters>
<!-- here-->
</cgb>
and I want to add 2 more "parameter" rows. When I use my function the
parameters are added where I put the comment line.

My function :

Dim ds As New DataSet
Dim reader As XmlReader = New XmlTextReader(New StringReader(xmlParameters))
ds.ReadXml(reader)
Dim row As DataRow
row = ds.Tables("parameter").NewRow
row("paramName") = paramName
row("paramValue") = paramValue
ds.Tables("parameter").Rows.Add(row)
Return ds.GetXml
What am I doing wrong ? I want my xml like this
<cgb>
<parameters>
<parameter>
<paramName>patientNr</paramName>
<paramValue>7507244765</paramValue>
</parameter>
<parameter>
<paramName>ApplicationKey</paramName>
<paramValue>cpd</paramValue>
</parameter>

<parameter>
<paramName>GUID</paramName>
<paramValue>84BA0FFC-2BE2-401f-A294-EFB00CA3A3A9</paramValue>
</parameter>
<parameter>
<paramName>SID</paramName>
<paramValue>01050000000000051500000071459C02367CDD 12DA1B396F41090000</paramValue>
</parameter>

</parameters>

</cgb>
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You need to set the parent row for your newly added row. Your dataset has
two tables, named "parameters" and "parameter." The "parameters" table has
one row (row 0). So, first you get a reference to that row, and then set
that as the parent for your newly created "parameter" row. Note that you
should add the relationship before adding the child row. For example:

Dim ds As New DataSet
Dim reader As XmlReader = New XmlTextReader(New StringReader(xmlParameters))
ds.ReadXml(reader)

Dim rowParent As DataRow = ds.Tables("parameters").Rows(0)
Dim row As DataRow
row = ds.Tables("parameter").NewRow
row("paramName") = paramName
row("paramValue") = paramValue
row.SetParent(rowParent)
ds.Tables("parameter").Rows.Add(row)
Return ds.GetXml

Now the output should look like you want it to.

"Gene Vangampelaere" <ge****************************@infohos.remove.thi s.be>
wrote in message news:uW**************@tk2msftngp13.phx.gbl...
Hi,

I'm having a frustrating problem :)
I have an XML like this :

<?xml version="1.0" encoding="utf-8"?>
<cgb>
<parameters>
<parameter>
<paramName>patientNr</paramName>
<paramValue>7507244765</paramValue>
</parameter>
<parameter>
<paramName>ApplicationKey</paramName>
<paramValue>cpd</paramValue>
</parameter>
</parameters>
<!-- here-->
</cgb>
and I want to add 2 more "parameter" rows. When I use my function the
parameters are added where I put the comment line.

My function :

Dim ds As New DataSet
Dim reader As XmlReader = New XmlTextReader(New
StringReader(xmlParameters))
ds.ReadXml(reader)
Dim row As DataRow
row = ds.Tables("parameter").NewRow
row("paramName") = paramName
row("paramValue") = paramValue
ds.Tables("parameter").Rows.Add(row)
Return ds.GetXml
What am I doing wrong ? I want my xml like this
<cgb>
<parameters>
<parameter>
<paramName>patientNr</paramName>
<paramValue>7507244765</paramValue>
</parameter>
<parameter>
<paramName>ApplicationKey</paramName>
<paramValue>cpd</paramValue>
</parameter>

<parameter>
<paramName>GUID</paramName>
<paramValue>84BA0FFC-2BE2-401f-A294-EFB00CA3A3A9</paramValue>
</parameter>
<parameter>
<paramName>SID</paramName>

<paramValue>01050000000000051500000071459C02367CDD 12DA1B396F41090000</paramValue>
</parameter>

</parameters>

</cgb>

Nov 21 '05 #2

P: n/a
thx !

"Russell Jones" <ar**@nospam.northstate.net> schreef in bericht
news:eO**************@TK2MSFTNGP12.phx.gbl...
You need to set the parent row for your newly added row. Your dataset has
two tables, named "parameters" and "parameter." The "parameters" table has
one row (row 0). So, first you get a reference to that row, and then set
that as the parent for your newly created "parameter" row. Note that you
should add the relationship before adding the child row. For example:

Dim ds As New DataSet
Dim reader As XmlReader = New XmlTextReader(New
StringReader(xmlParameters))
ds.ReadXml(reader)

Dim rowParent As DataRow = ds.Tables("parameters").Rows(0)
Dim row As DataRow
row = ds.Tables("parameter").NewRow
row("paramName") = paramName
row("paramValue") = paramValue
row.SetParent(rowParent)
ds.Tables("parameter").Rows.Add(row)
Return ds.GetXml

Now the output should look like you want it to.

"Gene Vangampelaere"
<ge****************************@infohos.remove.thi s.be> wrote in message
news:uW**************@tk2msftngp13.phx.gbl...
Hi,

I'm having a frustrating problem :)
I have an XML like this :

<?xml version="1.0" encoding="utf-8"?>
<cgb>
<parameters>
<parameter>
<paramName>patientNr</paramName>
<paramValue>7507244765</paramValue>
</parameter>
<parameter>
<paramName>ApplicationKey</paramName>
<paramValue>cpd</paramValue>
</parameter>
</parameters>
<!-- here-->
</cgb>
and I want to add 2 more "parameter" rows. When I use my function the
parameters are added where I put the comment line.

My function :

Dim ds As New DataSet
Dim reader As XmlReader = New XmlTextReader(New
StringReader(xmlParameters))
ds.ReadXml(reader)
Dim row As DataRow
row = ds.Tables("parameter").NewRow
row("paramName") = paramName
row("paramValue") = paramValue
ds.Tables("parameter").Rows.Add(row)
Return ds.GetXml
What am I doing wrong ? I want my xml like this
<cgb>
<parameters>
<parameter>
<paramName>patientNr</paramName>
<paramValue>7507244765</paramValue>
</parameter>
<parameter>
<paramName>ApplicationKey</paramName>
<paramValue>cpd</paramValue>
</parameter>

<parameter>
<paramName>GUID</paramName>
<paramValue>84BA0FFC-2BE2-401f-A294-EFB00CA3A3A9</paramValue>
</parameter>
<parameter>
<paramName>SID</paramName>

<paramValue>01050000000000051500000071459C02367CDD 12DA1B396F41090000</paramValue>
</parameter>

</parameters>

</cgb>


Nov 21 '05 #3

P: n/a
thx !

"Russell Jones" <ar**@nospam.northstate.net> schreef in bericht
news:eO**************@TK2MSFTNGP12.phx.gbl...
You need to set the parent row for your newly added row. Your dataset has
two tables, named "parameters" and "parameter." The "parameters" table has
one row (row 0). So, first you get a reference to that row, and then set
that as the parent for your newly created "parameter" row. Note that you
should add the relationship before adding the child row. For example:

Dim ds As New DataSet
Dim reader As XmlReader = New XmlTextReader(New
StringReader(xmlParameters))
ds.ReadXml(reader)

Dim rowParent As DataRow = ds.Tables("parameters").Rows(0)
Dim row As DataRow
row = ds.Tables("parameter").NewRow
row("paramName") = paramName
row("paramValue") = paramValue
row.SetParent(rowParent)
ds.Tables("parameter").Rows.Add(row)
Return ds.GetXml

Now the output should look like you want it to.

"Gene Vangampelaere"
<ge****************************@infohos.remove.thi s.be> wrote in message
news:uW**************@tk2msftngp13.phx.gbl...
Hi,

I'm having a frustrating problem :)
I have an XML like this :

<?xml version="1.0" encoding="utf-8"?>
<cgb>
<parameters>
<parameter>
<paramName>patientNr</paramName>
<paramValue>7507244765</paramValue>
</parameter>
<parameter>
<paramName>ApplicationKey</paramName>
<paramValue>cpd</paramValue>
</parameter>
</parameters>
<!-- here-->
</cgb>
and I want to add 2 more "parameter" rows. When I use my function the
parameters are added where I put the comment line.

My function :

Dim ds As New DataSet
Dim reader As XmlReader = New XmlTextReader(New
StringReader(xmlParameters))
ds.ReadXml(reader)
Dim row As DataRow
row = ds.Tables("parameter").NewRow
row("paramName") = paramName
row("paramValue") = paramValue
ds.Tables("parameter").Rows.Add(row)
Return ds.GetXml
What am I doing wrong ? I want my xml like this
<cgb>
<parameters>
<parameter>
<paramName>patientNr</paramName>
<paramValue>7507244765</paramValue>
</parameter>
<parameter>
<paramName>ApplicationKey</paramName>
<paramValue>cpd</paramValue>
</parameter>

<parameter>
<paramName>GUID</paramName>
<paramValue>84BA0FFC-2BE2-401f-A294-EFB00CA3A3A9</paramValue>
</parameter>
<parameter>
<paramName>SID</paramName>

<paramValue>01050000000000051500000071459C02367CDD 12DA1B396F41090000</paramValue>
</parameter>

</parameters>

</cgb>


Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.