XML writting, what´s wrong?

I

Ibai Peña

Hi,

I need to update a XML file in the PDA. I use this code for it.

string CodArt = txtArtic.Text.Trim();
string CodAct;
for (int i=0;i<TInvent.Rows.Count;i++)
{
CodAct=(string)TInvent.Rows.ItemArray.GetValue(0);
if (CodAct.Equals(CodArt))
TInvent.Rows.ItemArray.SetValue(Int32.Parse(txtExist.Text),4);
}
TInvent.DataSet.WriteXml(XMLFileName);

Where TInvent is a DataTable.

I have debugged, and the Row is updated. But the XML file is not updated.
What am I doing wrong?

Thanks in advance,
 
E

Erik J Rubin [MS]

I think WriteXml, by default, will not write out the modified rows' updated
contents. I think if you do a TInvent.DataSet.AcceptChanges() right before
writing the XML, then the XML will show the update.

Thanks

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Ibai Peña" <[email protected]>
| Subject: XML writting, what´s wrong?
| Date: Tue, 19 Aug 2003 11:26:17 +0200
| Lines: 25
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: 106.red-217-127-99.pooles.rima-tde.net 217.127.99.106
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:31301
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| Hi,
|
| I need to update a XML file in the PDA. I use this code for it.
|
| string CodArt = txtArtic.Text.Trim();
| string CodAct;
| for (int i=0;i<TInvent.Rows.Count;i++)
| {
| CodAct=(string)TInvent.Rows.ItemArray.GetValue(0);
| if (CodAct.Equals(CodArt))
| TInvent.Rows.ItemArray.SetValue(Int32.Parse(txtExist.Text),4);
| }
| TInvent.DataSet.WriteXml(XMLFileName);
|
| Where TInvent is a DataTable.
|
| I have debugged, and the Row is updated. But the XML file is not updated.
| What am I doing wrong?
|
| Thanks in advance,
|
| --
| Ibai Peña
|
|
|
 
I

Ibai Peña

I have tried doing AcceptChanges for both, the DataTable TInvent, and its
DataSet.
But still doesn´t update the XML.
I have search the web looking for some example of saving XML data with the
CF, but I havent found anything.
Could someone show me an example of saving XML data?

Thanks,
 
I

Ilya Tumanov [MS]

The problem is: you're not changing data in the DataTable.
ItemArray returns a _copy_ of row's data, so you're changing a copy.
As soon as it's changed, this copy is discarded as you do not keep a
reference to it.
This portion of code basically does nothing (not to count wasted time).
Stop using ItemArray and change data directly or assign changed ItemArray
back to the row to fix a problem.

Also, your code might be slow. For example, you could use something like
this to speed it up:

string CodArt = txtArtic.Text.Trim();

Int32 myValue = Int32.Parse(txtExist.Text); // Do parsing
outside the loop unless value changes each iteration.

DataRow[] rows = TInvent.Select( TInvent.Columns[0].ColumnName + "
= " + CodArt );
//
Select rows we need (change the expression as needed)
//
This is fast if you have an index.
foreach (DataRow row in rows ) { // For each
selected row...
row[0] = myValue; // Change
value in this row for column #0
row[1] = 4; // and
column #1
}

You might want to get a good book on ADO.Net.
It does not have to be about Compact Framework, desktop ADO.Net will do.
If you're switching from VB 6 it might be tough at first, so good ADO.Net
book is a necessity.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "Ibai Peña" <[email protected]>
References: <[email protected]>
Subject: Re: XML writting, what´s wrong?
Date: Wed, 20 Aug 2003 08:15:03 +0200
Lines: 71
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Message-ID: <eiw#[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: 106.red-217-127-99.pooles.rima-tde.net 217.127.99.106
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.compactframework:31411
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

I have tried doing AcceptChanges for both, the DataTable TInvent, and its
DataSet.
But still doesn´t update the XML.
I have search the web looking for some example of saving XML data with the
CF, but I havent found anything.
Could someone show me an example of saving XML data?

Thanks,
--
Ibai Peña

Erik J Rubin said:
I think WriteXml, by default, will not write out the modified rows' updated
contents. I think if you do a TInvent.DataSet.AcceptChanges() right before
writing the XML, then the XML will show the update.

Thanks

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Ibai Peña" <[email protected]>
| Subject: XML writting, what´s wrong?
| Date: Tue, 19 Aug 2003 11:26:17 +0200
| Lines: 25
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: 106.red-217-127-99.pooles.rima-tde.net 217.127.99.106
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:31301
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| Hi,
|
| I need to update a XML file in the PDA. I use this code for it.
|
| string CodArt = txtArtic.Text.Trim();
| string CodAct;
| for (int i=0;i<TInvent.Rows.Count;i++)
| {
| CodAct=(string)TInvent.Rows.ItemArray.GetValue(0);
| if (CodAct.Equals(CodArt))
| TInvent.Rows.ItemArray.SetValue(Int32.Parse(txtExist.Text),4);
| }
| TInvent.DataSet.WriteXml(XMLFileName);
|
| Where TInvent is a DataTable.
|
| I have debugged, and the Row is updated. But the XML file is not updated.
| What am I doing wrong?
|
| Thanks in advance,
|
| --
| Ibai Peña
|
|
|

 
I

Ibai Peña

Very glad for your answer.

It has help me a lot.

I will follow your advice and get a book as soon as I can.

--
Ibai Peña

"Ilya Tumanov [MS]" said:
The problem is: you're not changing data in the DataTable.
ItemArray returns a _copy_ of row's data, so you're changing a copy.
As soon as it's changed, this copy is discarded as you do not keep a
reference to it.
This portion of code basically does nothing (not to count wasted time).
Stop using ItemArray and change data directly or assign changed ItemArray
back to the row to fix a problem.

Also, your code might be slow. For example, you could use something like
this to speed it up:

string CodArt = txtArtic.Text.Trim();

Int32 myValue = Int32.Parse(txtExist.Text); // Do parsing
outside the loop unless value changes each iteration.

DataRow[] rows = TInvent.Select( TInvent.Columns[0].ColumnName + "
= " + CodArt );
//
Select rows we need (change the expression as needed)
//
This is fast if you have an index.
foreach (DataRow row in rows ) { // For each
selected row...
row[0] = myValue; // Change
value in this row for column #0
row[1] = 4; // and
column #1
}

You might want to get a good book on ADO.Net.
It does not have to be about Compact Framework, desktop ADO.Net will do.
If you're switching from VB 6 it might be tough at first, so good ADO.Net
book is a necessity.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
Subject: Re: XML writting, what´s wrong?
Date: Wed, 20 Aug 2003 08:15:03 +0200
Lines: 71
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Message-ID: <eiw#[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: 106.red-217-127-99.pooles.rima-tde.net 217.127.99.106
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.compactframework:31411
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

I have tried doing AcceptChanges for both, the DataTable TInvent, and its
DataSet.
But still doesn´t update the XML.
I have search the web looking for some example of saving XML data with the
CF, but I havent found anything.
Could someone show me an example of saving XML data?

Thanks,
--
Ibai Peña

"Erik J Rubin [MS]" <[email protected]> escribió en el mensaje
I think WriteXml, by default, will not write out the modified rows' updated
contents. I think if you do a TInvent.DataSet.AcceptChanges() right before
writing the XML, then the XML will show the update.

Thanks

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Ibai Peña" <[email protected]>
| Subject: XML writting, what´s wrong?
| Date: Tue, 19 Aug 2003 11:26:17 +0200
| Lines: 25
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: 106.red-217-127-99.pooles.rima-tde.net 217.127.99.106
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:31301
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| Hi,
|
| I need to update a XML file in the PDA. I use this code for it.
|
| string CodArt = txtArtic.Text.Trim();
| string CodAct;
| for (int i=0;i<TInvent.Rows.Count;i++)
| {
| CodAct=(string)TInvent.Rows.ItemArray.GetValue(0);
| if (CodAct.Equals(CodArt))
| TInvent.Rows.ItemArray.SetValue(Int32.Parse(txtExist.Text),4);
| }
| TInvent.DataSet.WriteXml(XMLFileName);
|
| Where TInvent is a DataTable.
|
| I have debugged, and the Row is updated. But the XML file is not updated.
| What am I doing wrong?
|
| Thanks in advance,
|
| --
| Ibai Peña
|
|
|


 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top