Solved

Clearing and XML DataSet

Posted on 2007-12-01
3
320 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

778 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