473,396 Members | 1,894 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,396 software developers and data experts.

How to save changes to XmlDataDocument?

I create an XmlDataDocument Dataset when the main form of my WinForms app
opens. The user will make changes to the Dataset, and then those changes
should be saved to the XML file when the code runs xdd.Save(xmlFile). But I
get an error when I try to save the Dataset back to the XML file: "The
process cannot access the file "C:\Projects.xml" because it is being used by
another process." Is this because I'm in Debug mode? How do I persist
changes to the XML file? Thanks in advance.

public class frmMain : System.Windows.Forms.Form
{
string xmlSchema = (@"C:\Projects.xsd");
string xmlFile = (@"C:\Projects.xml");
//[code omitted]

XmlDataDocument xdd = new XmlDataDocument();

public frmMain()
{
xdd.DataSet.ReadXmlSchema(xmlSchema);
XmlTextReader xrd = new XmlTextReader(xmlFile);
xrd.MoveToContent();
xdd.Load(xrd);
}

private void btnAddCfg_Click(object sender, System.EventArgs e)
{
DataTable someTbl = xdd.DataSet.Tables["Configuration"];
DataRow newCfg = someTbl.NewRow();
newCfg["ConfigName"] = "NEW CONFIGURATION";
prjTbl.Rows.Add(newCfg);
dsDebug.DebugWriteLine(xdd.DataSet);
//xdd.Save(xmlFile); //does not work // <<== * * ERROR HERE
//error rec'd says can't save while file is open
//but there must be a way to persist the changes
//is the error because I'm in debug mode and VS is open?
}
}
Nov 16 '05 #1
2 2285
Try closing your Xml object(s).
-----Original Message-----
I create an XmlDataDocument Dataset when the main form of my WinForms appopens. The user will make changes to the Dataset, and then those changesshould be saved to the XML file when the code runs xdd.Save(xmlFile). But Iget an error when I try to save the Dataset back to the XML file: "Theprocess cannot access the file "C:\Projects.xml" because it is being used byanother process." Is this because I'm in Debug mode? How do I persistchanges to the XML file? Thanks in advance.

public class frmMain : System.Windows.Forms.Form
{
string xmlSchema = (@"C:\Projects.xsd");
string xmlFile = (@"C:\Projects.xml");
//[code omitted]

XmlDataDocument xdd = new XmlDataDocument();

public frmMain()
{
xdd.DataSet.ReadXmlSchema(xmlSchema);
XmlTextReader xrd = new XmlTextReader(xmlFile);
xrd.MoveToContent();
xdd.Load(xrd);
}

private void btnAddCfg_Click(object sender, System.EventArgs e) {
DataTable someTbl = xdd.DataSet.Tables["Configuration"];
DataRow newCfg = someTbl.NewRow();
newCfg["ConfigName"] = "NEW CONFIGURATION";
prjTbl.Rows.Add(newCfg);
dsDebug.DebugWriteLine(xdd.DataSet);
//xdd.Save(xmlFile); //does not work // <<== * * ERROR HERE
//error rec'd says can't save while file is open
//but there must be a way to persist the changes
//is the error because I'm in debug mode and VS is open?
}
}
.

Nov 16 '05 #2
> Try closing your Xml object(s).

Thanks for the reply. I am kind of green... can you provide an example of
how to do this?

Thanks.
Nov 16 '05 #3

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

Similar topics

1
by: Mathew Relick | last post by:
I'm relatively new to this sort of thing, so forgive me if this is completely off base, but I'm having a problem getting the XMLDataDocument to do what I need it to. I have a small test...
1
by: Peter Feakins | last post by:
We're building some web services that are primarily being consumed by a .net application. We're returning datasets for that purpose. We're also have to provide access to these services to classic...
0
by: Raj | last post by:
hi, I associate dataset with one xmldatadocument? how can I disassociate from xmldatadocument, so I can associate with another xmldatadocument. and, how can I remove xmldatadocument from...
0
by: gilly3 | last post by:
Reposting to a more relevant group. I am passing a generic dataset into a new XMLDataDocument and then parsing the XML with XSLT. The idea being that I can parse any dataset with the same xslt,...
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"),...
1
by: Petr Felzmann | last post by:
Hi, why the duration of call the CloneNode(true) is steadily increasing? First call is 0.004s and 100th is 0.16s! XML file is 5kB only, no disk swap. XmlDataDocument xml = new...
4
by: Jae | last post by:
I'm writing a web application that exports and imports excel files. The application gets a list of users and their info and displays it in a datagrid .The user then selects to save the file as a...
0
by: Steve | last post by:
I have a dataset. I fill it with two recordsets from SQL queries. Tables are called tblPlanFYSpendingStage, tblSpendingStage.
4
by: Adrian Meyer | last post by:
Hi, On the server I code the following web service: ))] public XmlDataDocument GetTypedXmlDataDocument() { sqlDataAdapter1.Fill(typedDataSet1); XmlDataDocument dataDoc
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.