Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.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# 如何将xml读入数据表类型对象?_C#_.net_Xml_Datatable_Dataset - Fatal编程技术网

C# 如何将xml读入数据表类型对象?

C# 如何将xml读入数据表类型对象?,c#,.net,xml,datatable,dataset,C#,.net,Xml,Datatable,Dataset,如果我将xml读入数据集,我没有问题: DataSet temp = new DataSet(); temp.ReadXml(UncompressedStream, System.Data.XmlReadMode.Auto); 但是如果我使用数据表: DataTable temp = new DataTable(); temp.ReadXml(UncompressedStream); 然后datatable不加载数据(列和行的计数等于0) 如何将xml读入数据表 我的临时解决办法: Data

如果我将xml读入
数据集
,我没有问题:

DataSet temp = new DataSet();
temp.ReadXml(UncompressedStream, System.Data.XmlReadMode.Auto);
但是如果我使用
数据表

DataTable temp = new DataTable();
temp.ReadXml(UncompressedStream);
然后datatable不加载数据(列和行的计数等于0)

如何将xml读入数据表

我的临时解决办法:

DataSet temp = new DataSet();
DataTable structure = new DataTable();
temp.ReadXml(UncompressedStream, System.Data.XmlReadMode.Auto);
structure = temp.Tables[0];
可能是您正在寻找的东西。

可能是您正在寻找的东西。

私有静态无效演示器ReadWriteXmlDocumentWithString()
private static void DemonstrateReadWriteXMLDocumentWithString()
{
    DataTable table = CreateTestTable("XmlDemo");
    PrintValues(table, "Original table");

    string fileName = "C:\\TestData.xml";
    table.WriteXml(fileName, XmlWriteMode.WriteSchema);

    DataTable newTable = new DataTable();
    newTable.ReadXml(fileName);

    // Print out values in the table.
    PrintValues(newTable, "New table");
}

private static DataTable CreateTestTable(string tableName)
{
    // Create a test DataTable with two columns and a few rows.
    DataTable table = new DataTable(tableName);
    DataColumn column = new DataColumn("id", typeof(System.Int32));
    column.AutoIncrement = true;
    table.Columns.Add(column);

    column = new DataColumn("item", typeof(System.String));
    table.Columns.Add(column);

    // Add ten rows.
    DataRow row;
    for (int i = 0; i <= 9; i++)
    {
        row = table.NewRow();
        row["item"] = "item " + i;
        table.Rows.Add(row);
    }

    table.AcceptChanges();
    return table;
}
{ DataTable=CreateTestTable(“XmlDemo”); 打印值(表,“原始表”); string fileName=“C:\\TestData.xml”; table.WriteXml(文件名,XmlWriteMode.WriteSchema); DataTable newTable=新DataTable(); newTable.ReadXml(文件名); //打印表中的值。 打印值(新表,“新表”); } 私有静态数据表CreateTestTable(字符串表名) { //创建一个包含两列和几行的测试数据表。 DataTable=新的DataTable(tableName); DataColumn column=新的DataColumn(“id”,typeof(System.Int32)); column.AutoIncrement=true; 表.列.添加(列); column=新数据列(“项”,typeof(System.String)); 表.列.添加(列); //加十行。 数据行; 对于(int i=0;i
private static void DemonstrateReadWriteXMLDocumentWithString())
{
DataTable=CreateTestTable(“XmlDemo”);
打印值(表,“原始表”);
string fileName=“C:\\TestData.xml”;
table.WriteXml(文件名,XmlWriteMode.WriteSchema);
DataTable newTable=新DataTable();
newTable.ReadXml(文件名);
//打印表中的值。
打印值(新表,“新表”);
}
私有静态数据表CreateTestTable(字符串表名)
{
//创建一个包含两列和几行的测试数据表。
DataTable=新的DataTable(tableName);
DataColumn column=新的DataColumn(“id”,typeof(System.Int32));
column.AutoIncrement=true;
表.列.添加(列);
column=新数据列(“项”,typeof(System.String));
表.列.添加(列);
//加十行。
数据行;
对于(int i=0;i