D
David
Hi all,
Using C# 1.1
I have a dataset loaded from an XML file. The idea being that if the app (a
winform app that relies on a webservice) is offline, then I save data
locally in XML and update the web service later.
So, when I update, I have something like...
DataSet siteLinks = new DataSet();
siteLinks.ReadXml(WorkingDirectory + @"\temp\SaveLinks.xml");
// Upload Link Data.
foreach (DataRow dr in siteLinks.Tables[0].Rows)
{
try
{
if (uploaddatatowebservice) // Saves data into webservice and
returns boolean
{
// Remove the row once it has been processed.
dr.Delete();
}
else
{
MessageBox.Show("There was a problem saving the link. If problems
persist, please contact the administrator.");
}
}
catch(Exception ex)
{
string exc = ex.Message;
}
}
if (siteLinks.HasChanges())
{
siteLinks.AcceptChanges();
}
However, I get a problem... dr is the datarow from the dataset. I try and
delete the datarow (which seems to work, though is not actually deleted from
the XML at this point) but on the next iteration of the loop, I get a
System.InvalidOperationException Collection was modified; enumeration
operation may not execute.
What am I doing wrong?
Also, will what I have here actually save the changes back into the XML? If
not, what am I missing?
Thanks.
--
Best regards,
Dave Colliver.
http://www.LincolnFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
Using C# 1.1
I have a dataset loaded from an XML file. The idea being that if the app (a
winform app that relies on a webservice) is offline, then I save data
locally in XML and update the web service later.
So, when I update, I have something like...
DataSet siteLinks = new DataSet();
siteLinks.ReadXml(WorkingDirectory + @"\temp\SaveLinks.xml");
// Upload Link Data.
foreach (DataRow dr in siteLinks.Tables[0].Rows)
{
try
{
if (uploaddatatowebservice) // Saves data into webservice and
returns boolean
{
// Remove the row once it has been processed.
dr.Delete();
}
else
{
MessageBox.Show("There was a problem saving the link. If problems
persist, please contact the administrator.");
}
}
catch(Exception ex)
{
string exc = ex.Message;
}
}
if (siteLinks.HasChanges())
{
siteLinks.AcceptChanges();
}
However, I get a problem... dr is the datarow from the dataset. I try and
delete the datarow (which seems to work, though is not actually deleted from
the XML at this point) but on the next iteration of the loop, I get a
System.InvalidOperationException Collection was modified; enumeration
operation may not execute.
What am I doing wrong?
Also, will what I have here actually save the changes back into the XML? If
not, what am I missing?
Thanks.
--
Best regards,
Dave Colliver.
http://www.LincolnFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available