Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Clearing and XML DataSet

Posted on 2007-12-01
3
Medium Priority
?
335 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 48

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 1500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

597 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