Solved

Clearing and XML DataSet

Posted on 2007-12-01
3
321 Views
Last Modified: 2013-12-16
Hi guys,

I'm trying to clear an XML DataSet that was populated as follow but it's not working:

DataSet ds = new DataSet();
ds.ReadXml("path to xml", XmlReadMode.InferSchema);

ds.Clear();

Here's what MSDN is saying:

"If the DataSet is bound to an XmlDataDocument, calling DataSet.Clear or DataTable.Clear raises the NotSupportedException. To avoid this situation, traverse each table, removing each row one at a time."

http://msdn2.microsoft.com/en-us/library/system.data.dataset.clear.aspx

Does this apply to my case? If so, how can I do it?

Thanks.
0
Comment
Question by:EEssam
  • 2
3 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 20390339
Hi EEssam,

As suggested,  traverse each table, removing each row one at a time.....

     {
         foreach (DataTable dt in ds.Tables) {
             foreach (DataRow dr in dt.Rows) {
                 dr.Delete();
             }
         }
     }

Regards,

Wayne
0
 

Author Comment

by:EEssam
ID: 20392033
Hi,

Your code is giving an exception when executed.

System.InvalidOperationException: Collection was modified; enumeration operation might not execute.
0
 

Author Comment

by:EEssam
ID: 20393150
ds.Clear(); works with XML in my case. I just was missing something in my code... However, I'll accept your solution because it does the job as well.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question