Solved

Clearing and XML DataSet

Posted on 2007-12-01
3
322 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 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