Solved

Clearing and XML DataSet

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now