Does any body know how to write an XML from a Dataset that has multiple tables with multiple parent rows?
Scenario:
I have five children relations to a table, this makes 5 foreign keys on the parent table; and this parent table has its own parent.
All Tables contain data and I want to export it to an XML file.
In order to do this, the code I use is:
DataSet dataSet = dataSource as DataSet;
SaveFileDialog dialog = new SaveFileDialog();
dialog.FileName = dataSet.DataSetName;
dialog.Filter = "XML files (*.xml) | *.xml";
if (dialog.ShowDialog() == DialogResult.OK)
{
dataSet.EnforceConstraints = false;
dataSet.WriteXml(dialog.FileName, XmlWriteMode.WriteSchema);
}
Every time I debug and hit the dataSet.WriteXml line I get this error message:
Cannot proceed with serializing DataTable 'Table_Name'. It contains a
DataRow which has multiple parent rows on the same Foreign Key.
Any ideas on why this happens and how to solve it?
Thanks in advance.
The problem was resolved after deleting the data in a table and new data was inserted. Since the DB does not have a constraint and the constraint is upon the dataset’s FK relationship, thare is were it failed.
The proper solution is to set up a FK constraint in the database, instead of doing it in the dataset alone.
Thanks guys, your answers guide me through.