473,417 Members | 1,623 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,417 software developers and data experts.

Removing association between DataSet and XmlDataDocument

JD
I have a DataGridView with a DataSet as DataSource. The user can
update the contents of the DataGridView, and then click on a Save
button to save the data to an XML file.

When they click on Save, I call the subroutine below. The first time
that I call it, it works fine. However, if the user makes some more
changes in the DataGridView and then wants to save again, I get the
following error message:

"DataSet can be associated with at most one XmlDataDocument. Cannot
associate the DataSet with the current XmlDataDocument because the
DataSet is already associated with another XmlDataDocument."

This occurs on the line that I indicated. I can see what's wrong, but
I can't work out how to remove the association between the DataSet and
the XmlDataDocument at the end of the sub. Tried adding the line
"xmlDoc = Nothing" at the end, but didn't work.
Private Sub SaveDataSetToXml(ByVal filePath, ByRef DataSet)
Dim xmlDoc As System.Xml.XmlDataDocument
Dim xmlDec As System.Xml.XmlDeclaration
Dim xmlWriter As System.Xml.XmlWriter

xmlWriter = New
System.Xml.XmlTextWriter(My.Computer.FileSystem.Op enTextFileWriter(filePath,
False))

xmlDoc = New System.Xml.XmlDataDocument(DataSet) ' This is the line
that gives an error
xmlDoc.DataSet.EnforceConstraints = False
xmlDec = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", Nothing)
xmlDoc.PrependChild(xmlDec)

xmlDoc.WriteTo(xmlWriter)
xmlWriter.Flush()
xmlWriter.Close()
End Sub

Mar 16 '07 #1
1 2857
JD
On Mar 16, 12:32 pm, "JD" <TheEvilDj...@gmail.comwrote:
This occurs on the line that I indicated. I can see what's wrong, but
I can't work out how to remove the association between the DataSet and
the XmlDataDocument at the end of the sub. Tried adding the line
"xmlDoc = Nothing" at the end, but didn't work.
<snip>

OK I figured something out myself. Shows how much it can help to
actually write out a description of your problem, I had been
scratching my head on this for 2-3 hours before I posted!

Now I call the sub with a /copy/ of the DataSet, and then do a
DataSet.Dispose just before the end of the sub, and then I don't get
any error message. Is this an efficient way to do it?

Mar 16 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tom Vukovich | last post by:
and returning the xml to the requesting web page, how do you insert the XML declaration? ds.EnforceConstraints = False Response.ContentType = "text/xml" ds.WriteXml(Response.OutputStream,...
1
by: Matthew Baskey | last post by:
Hello, I need to reorder a Typed DataSet in memory using an Xsl Transform. Most of the examples use stream which write to the hard disk or xml file. I want to do this in memory and then write...
4
by: geilen | last post by:
I'm trying to use a dataset returned from a web service in an unmanaged C++ (MFC) client. The dataset is returned as a BSTR, and I'm having trouble reading the BSTR into an XML document for...
2
by: James Ankrom | last post by:
Why does this fail? Dim relResources As New Data.DataRelation("Application_Resources", ..Tables("User_Applications").Columns("Application_id"),...
3
by: Wolfgang Woznik | last post by:
Hello, I have a Client/Server system based on a single generic communication method using XML (as done in MS Project-Server or SharePoint-WebServices). To transfer DataSets I'am using...
0
by: Steve | last post by:
I have a dataset. I fill it with two recordsets from SQL queries. Tables are called tblPlanFYSpendingStage, tblSpendingStage.
2
by: ERingmae | last post by:
Hi, The environment is .NET 2.0, the language is C# and the problem is reading XSD file with xs:redefine section correctly to a XMLDataDocument.DataSet. What I am trying to do: I am trying...
0
by: OscarPiacenza | last post by:
Hello all. :) My name is Oscar and I’m a novice on XML and dataset arguments. I need some help to resolve (and understand :) ) the following problem: I have stored some data in a SqlServer...
5
by: Tony Johansson | last post by:
Hello! Xml is used havily when dealing with DataSet. I know that Xml schema is used by DataSet. Xml schema is used to verify the structure of an Xml document. So does this mean that a DataSet...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.