Working with XML files

G

Guest

Hi all!

I have a XML file that is read by a C# program.
The file looks like this:

<EMailList>
<email>[email protected]</email>
</EMailList>
<EMailList>
<email>[email protected]</email>
</EMailList>

But I want that this file look like this:

<EMailList>
<email>[email protected]</email>
<email>[email protected]</email>
</EMailList>

But, when I do that my program blows up.

The code to read the file is that:

public class COpicsXMLOperations
{

#region XMLConfigFile
static public DataSet dsOpicsSystemBuilder;
static public DataSet dsOpicsSBUsers;
#endregion

static public DataSet DS_OpicsSystemBuilder
{
get
{
if (dsOpicsSystemBuilder==null)
{
dsOpicsSystemBuilder = new DataSet();

// Creating EMailList table
DataTable dtEMailList = new DataTable("EMailList");
DataColumn dcEMail = new DataColumn("email");
dtEMailList.Columns.Add(dcEMail);
dsOpicsSystemBuilder.Tables.Add(dtEMailList);
}
return dsOpicsSystemBuilder;
}
}

private void FrmProcParam_Load(object sender, System.EventArgs e)
{
// Clear the list to avoid duplicates
clb_EMails.Items.Clear();
this.txt_Emails.Focus();

// Read the e-mails against the XML file
COpicsXMLOperations.DS_OpicsSystemBuilder.Tables.Clear();
COpicsXMLOperations.DS_OpicsSystemBuilder.ReadXml("OpicsSystemBuilder.xml");
This is the line that blows up.

The error is:

An unhandled exception of type 'System.ArgumentException' occurred in
system.data.dll

Additional information: Cannot remove a table that has existing relations.
Remove relations first.

The program '[2304] OpicsSystemBuilder.exe' has exited with code 0 (0x0).

Anybody can help me with this?

Thanks!

Eduardo

--
Eduardo de Morais Ferrari
Misys'' OPICS Project
Stefanini IT Solutions
White Plains, NY
Phone: (914) 821-2727
Cell: (914) 406-5027
(e-mail address removed)
 
G

Guest

Hi Tim!

Yes, I did. And I did not set any relations on this table.

Eduardo
--
Eduardo de Morais Ferrari
Misys'''''''' OPICS Project
Stefanini IT Solutions
White Plains, NY
Phone: (914) 821-2727
Cell: (914) 406-5027
(e-mail address removed)


Tim_Mac said:
hi Eduardo,
did you try clearing the relations as the error suggested?
somewhere along the way, a relation must be created between tables in the
dataset. the first version of your xml file includes multiple tables, this
could be the reason for a relation being inferred unless you created them
yourself. you could debug before the error happens and examine the
Dataset.Relations property to see what kind of relation exists.

hope this helps
tim
--------------------------
blog: http://tim.mackey.ie


Ferrari said:
Hi all!

I have a XML file that is read by a C# program.
The file looks like this:

<EMailList>
<email>[email protected]</email>
</EMailList>
<EMailList>
<email>[email protected]</email>
</EMailList>

But I want that this file look like this:

<EMailList>
<email>[email protected]</email>
<email>[email protected]</email>
</EMailList>

But, when I do that my program blows up.

The code to read the file is that:

public class COpicsXMLOperations
{

#region XMLConfigFile
static public DataSet dsOpicsSystemBuilder;
static public DataSet dsOpicsSBUsers;
#endregion

static public DataSet DS_OpicsSystemBuilder
{
get
{
if (dsOpicsSystemBuilder==null)
{
dsOpicsSystemBuilder = new DataSet();

// Creating EMailList table
DataTable dtEMailList = new DataTable("EMailList");
DataColumn dcEMail = new DataColumn("email");
dtEMailList.Columns.Add(dcEMail);
dsOpicsSystemBuilder.Tables.Add(dtEMailList);
}
return dsOpicsSystemBuilder;
}
}

private void FrmProcParam_Load(object sender, System.EventArgs e)
{
// Clear the list to avoid duplicates
clb_EMails.Items.Clear();
this.txt_Emails.Focus();

// Read the e-mails against the XML file
COpicsXMLOperations.DS_OpicsSystemBuilder.Tables.Clear();
COpicsXMLOperations.DS_OpicsSystemBuilder.ReadXml("OpicsSystemBuilder.xml");
This is the line that blows up.

The error is:

An unhandled exception of type 'System.ArgumentException' occurred in
system.data.dll

Additional information: Cannot remove a table that has existing relations.
Remove relations first.

The program '[2304] OpicsSystemBuilder.exe' has exited with code 0 (0x0).

Anybody can help me with this?

Thanks!

Eduardo

--
Eduardo de Morais Ferrari
Misys'' OPICS Project
Stefanini IT Solutions
White Plains, NY
Phone: (914) 821-2727
Cell: (914) 406-5027
(e-mail address removed)
 
Top