Click here to Skip to main content
15,877,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've tried online help and Goggle and I can't find any answer to this. When I call dataset.WritXML(string filename) after creating a new "Project" row my program appears to write all the existing rows then the new row and then repeats all the existing rows again. I've tried deleting the XML file after starting the program and before saving to see if it was just appending the data to the existing file but I still get the same output. I've looked at the dataset value when debugging and they look fine, no repeated rows.

I think there might be a problem with my schema file:
XML
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="ProjectCommander" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="ProjectCommander" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="Project">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="LastChangeNotice" type="xs:string" minOccurs="0" msdata:Ordinal="0" />
              <xs:element name="LastSiteInstruction" type="xs:string" minOccurs="0" msdata:Ordinal="1" />
              <xs:element name="MilestoneItem" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="Date" type="xs:string" minOccurs="0" />
                    <xs:element name="Event" type="xs:string" minOccurs="0" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="CommentItem" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="Date" type="xs:string" minOccurs="0" />
                    <xs:element name="Description" type="xs:string" minOccurs="0" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="ProjectID" type="xs:string" />
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>


Can anyone see anything wrong?
Posted

My guess is that you have two tables in your DataSet and they are both being written out.
 
Share this answer
 
Comments
Paul Hildebrandt 4-Feb-11 23:49pm    
When I drill down into the dataset in the debugger I only see 3 tables. One for "Project", one for "MilestoneItem" and one for "CommentItem". Which is what I expect to see.
Steve Wellens 5-Feb-11 0:01am    
When you WriteXml everything in the DataSet gets saved. All three of your tables. Is that what you want?

You can also call WriteXml on a individual table.

It is also possible you have somehow added extra data to the table and it is saving accurately.
Paul Hildebrandt 5-Feb-11 0:28am    
Below is the code I use to add a new "Project" row:

<pre>ProjectCommander.ProjectRow row = projectCommander.Project.NewRow() as ProjectCommander.ProjectRow;
row["ProjectID"] = _projectName;
row["LastChangeNotice"] = "none";
row["LastSiteInstruction"] = "none";
projectCommander.Project.AddProjectRow(row);
projectCommander.AcceptChanges();</pre>
All the bound window components show the correct information just the writeXML is messed up.
Turns out I was reading the XML file a couple times without clearing the old data first. Odd thing is the IDE didn't show the extra rows when I was debugging.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900