Problem writing to an XML file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have added an XML file to my project and set it up like so:

<rotas xmlns = "http:\\ etc..">
<Managers>
<manager ID = "1" FirstName = "Bill" LastName = "Gates"<\manager>
<\Managers>
<\rotas>

Now, when I add a new manager row to this table called Managers, it doesn't
appear between the <Managers> tags, but instead it appears just below it. I
then have difficulty in deleting a new file as it can't be found, probably
due to this error.

The syntax I am using to add a new manager row is:

DataRow row = rotas1.manager.NewRow();
string [] ar = new string [3] {txtID.Text, txtFirstName.Text,
txtLastName.Text};

for(int i = o; i<ar.Length; i++)
{
row = ar;
}
rotas1.manager.Rows.Add(row);
rotas1.WriteXml("..\\..\\XMLFile1.xml");

Can anyone please point me in the right direction.
 
You need to associate the poor orphan with it's parent. Try this
before you add the row:
row.ManagersRow=rotas1.Managers[0];

Or, even better, just use this line:
rotas1.manager.AddmanagerRow(
txtID.Text, txtFirstName.Text, txtLastName.Text,
rotas1.Managers[0]
);

Peace,
Brett
I have added an XML file to my project and set it up like so:

<rotas xmlns = "http:\\ etc..">
<Managers>
<manager ID = "1" FirstName = "Bill" LastName =
Gates said:
<\Managers>
<\rotas>

Now, when I add a new manager row to this table called Managers, it doesn't
appear between the <Managers> tags, but instead it appears just below it. I
then have difficulty in deleting a new file as it can't be found, probably
due to this error.

The syntax I am using to add a new manager row is:

DataRow row = rotas1.manager.NewRow();
string [] ar = new string [3] {txtID.Text, txtFirstName.Text,
txtLastName.Text};

for(int i = o; i<ar.Length; i++)
{
row = ar;
}
rotas1.manager.Rows.Add(row);
rotas1.WriteXml("..\\..\\XMLFile1.xml");

Can anyone please point me in the right direction.
 
Back
Top