Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DataSource WriteXML打印关联父级的子行_C#_Dataset_Writexml - Fatal编程技术网

C# DataSource WriteXML打印关联父级的子行

C# DataSource WriteXML打印关联父级的子行,c#,dataset,writexml,C#,Dataset,Writexml,在我的数据库中,我有一个父表和子表。 例如,父表包含姓和地址,子表包含姓和名。 有一个外键,所以子表中的行在父表中必须具有相应的姓氏 当我使用2个DataAdapter读取这两个表,并将这些DataTable添加到DataSet时,我想打印XML,如下所示: <parent_table> <last_name>Smith</last_name> <address>111 Hi Street, Bye city</address>

在我的数据库中,我有一个父表和子表。 例如,父表包含姓和地址,子表包含姓和名。 有一个外键,所以子表中的行在父表中必须具有相应的姓氏

当我使用2个DataAdapter读取这两个表,并将这些DataTable添加到DataSet时,我想打印XML,如下所示:

<parent_table>
  <last_name>Smith</last_name>
  <address>111 Hi Street, Bye city</address>
  <child_table>
    <last_name>Smith</last_name>
    <first_name>Ann</first_name>
  </child_table>
  <child_table>
    <last_name>Smith</last_name>
    <first_name>Bob</first_name>
  </child_table>
</parent_table>

史密斯
拜拜城喜街111号
史密斯
安
史密斯
上下快速移动
但是,目前我将分别打印两张表:

<parent_table>
  <last_name>Smith</last_name>
  <address>111 Hi Street, Bye city</address>
</parent_table>
<child_table>
  <last_name>Smith</last_name>
  <first_name>Ann</first_name>
</child_table>
<child_table>
  <last_name>Smith</last_name>
  <first_name>Bob</first_name>
</child_table>

史密斯
拜拜城喜街111号
史密斯
安
史密斯
上下快速移动
有没有办法实现(希望使用DataSet.WriteXML())我想要的输出

我尝试添加ForeignKeyConstraint,并尝试添加DataRelation,但都没有更改输出

免责声明:以上内容是手写的,如果XML中有错误,请原谅。实际的表包含比“姓氏”更好的外键。

从写入:

在编写包含以下内容的数据集的XML表示形式时 对于DataRelation对象,您很可能希望生成的XML 将每个关系的子行嵌套在其相关关系中 父元素。要完成此操作,请设置 将DataRelation添加到数据集时,将DataRelation设置为true。对于 有关详细信息,请参阅