Serialization Problem Using WriteXML Method

What I'm trying to do with the code is to export a dataset to XML.

This is what I am using now:

dataSet.WriteXml(fileDialog.FileName, XmlWriteMode.WriteSchema);

My dataSet is a typed dataset, correctly formed (I mean that all tables have PK, and FK relationships are established between all existing tables in the dataSet). Some relationships are nested relationships. The table "TABLE" has two FKs and at the same time is the parent for the other 8 tables.

I get the following error: "Cannot continue serializing the DataTable" TABLE. "It contains a DataRow that has multiple parent rows on the same foreign key."

Will someone give me some guidance on what I'm doing wrong? and why am I getting this error message?

Thanks in advance.

0
source share
2 answers

I know this a bit later, but I found a workaround.

I ran into the same problem while trying to read a schema in a dataset that has a relationship. The error you get in this case: "The same table" {0} "cannot be a child table in two nested relationships" I will tell you what I found out

The dataset works in two modes, although you CANNOT say it outside.

  • (a) I am a strict / manually created dataset, I do not like nested relationships
  • (b) I am a container for a serialized object, everything goes.

, , "a", "b". , , DatSet "" (xml) .

DataSet, , , MS . DataRelation: http://referencesource.microsoft.com/#System.Data/System/Data/DataRelation.cs,d2d504fafd36cd26,references , , ValidateMultipleNestedRelations.)

, , , . , , - , , .

( , , DataSet.)

, :

  • , . , MS ( , ).
  • ( , )
  • MS, . ( )
  • .
  • , MS , .

, . DataSet NO Key-Columns, 'b', 'a'. , "b" "" " ", .

, , , "", , .

, sourceDataSet DataSet . :

var sourceDataSet = new DataSet();
var source = sourceDataSet.Serialize();
// todo: create the structure of your dataset.
var endTagKeyColumn = " msdata:AutoIncrement=\"true\" type=\"xs:int\" msdata:AllowDBNull=\"false\" use=\"prohibited\" /";
var endTagKeyColumnLength = endTagKeyColumn.Length - 1;

var startTagConstraint = "<xs:unique ";
var endTagConstraint = "</xs:unique>";
var endTagConstraintLength = endTagConstraint.Length - 1;

var cleanedUp = new StringBuilder();
var subStringStart = 0;
var subStringEnd = source.IndexOf(endTagKeyColumn);

while (subStringEnd > 0)
{
    // throw away unused key columns.
    while (source[subStringEnd] != '<') subStringEnd--;
    if (subStringEnd - subStringStart > 5)
    {
        cleanedUp.Append(source.Substring(subStringStart, subStringEnd - subStringStart));
    }
    subStringStart = source.IndexOf('>', subStringEnd + endTagKeyColumnLength) + 1;
    subStringEnd = source.IndexOf(endTagKeyColumn, subStringStart);
}

subStringEnd = source.IndexOf(startTagConstraint, subStringStart);
while (subStringEnd > 0)
{
    // throw away relationships.
    if (subStringEnd - subStringStart > 5)
    {
        cleanedUp.Append(source.Substring(subStringStart, subStringEnd - subStringStart));
    }
    subStringStart = source.IndexOf(endTagConstraint, subStringEnd) + endTagConstraintLength;
    subStringEnd = source.IndexOf(startTagConstraint, subStringStart);
}
cleanedUp.Append(source.Substring(subStringStart + 1));
target = new DataSet();
using (var reader = new StringReader(cleanedUp.ToString()))
{
    target.EnforceConstraints = false;
    target.ReadXml(reader, XmlReadMode.Auto);
}

, , , , , , .

+2

. , . XML ( , ). (, , ), , , dataSet, EnforceConstraints false.

+1

All Articles