DataTable does not support schema inference from Xml.?

后端 未结 5 1080
夕颜
夕颜 2020-12-08 13:01


  
    11
    22
    

        
相关标签:
5条回答
  • 2020-12-08 13:53

    If you are the one writing the table, you can solve this problem by writing the schema at the same time as the table. See: http://msdn.microsoft.com/en-us/library/ms135456.aspx

    0 讨论(0)
  • 2020-12-08 13:56

    Try using a Dataset rather

    DataSet ds = new DataSet();
    ds.ReadXml(@"d:\test.xml");
    MessageBox.Show(ds.Tables[0].Rows[0]["ID"].ToString());
    

    Found at

    DataTable.ReadXml(filename) throws an error. Why?

    0 讨论(0)
  • 2020-12-08 13:59

    If you're reading an XML file from DataTable.WriteXml, make sure you include an XmlWriteMode.WriteSchema.

    Example:

    Table.WriteXml(DataFilePath, XmlWriteMode.WriteSchema);
    
    0 讨论(0)
  • 2020-12-08 14:00

    This works

            string XML = @"
              <MyTable>
                <MyRecord>
                  <Col_1>test</Col_1>
                  <Col_2>1234</Col_2>
                </MyRecord>
                <MyRecord>
                  <Col_1>Record 2</Col_1>
                  <Col_2>2</Col_2>
                </MyRecord>
              </MyTable>
            ";
            DataSet DS = new DataSet();
            DS.ReadXml(new StringReader(XML));
    
            DataTable DT=DS.Tables[0];
    
    0 讨论(0)
  • 2020-12-08 14:04

    Try this, this will work :

    System.Xml.XmlTextReader reader =
                    new System.Xml.XmlTextReader(@"C:\Users\Mayank\Documents\Projects\XMLTEST\XMLTEST\XMLFile1.xml");
                DataSet newTable = new DataSet();
                newTable.ReadXml(reader);
                DataTable _dt=newTable.Tables[0];
    
    0 讨论(0)
提交回复
热议问题