locked
DataSet statment RRS feed

  • Question

  • User1077245351 posted

    Which of the following statements is True

    dataSet ds = new DataSet();

    ds.ReadXML("..\..\states.xml", XmlReadMode Auto);

    Responses:

    1. XML data cannot be read into DataSet
    2. The code will run successfully
    3. There are missing verbatim string literals at line 2

    I think the right answer will be number 2, correct?

    Your help is appreciated.  Thanks

    Wednesday, March 6, 2019 1:31 AM

Answers

  • User-893317190 posted

    Hi slb2012,

    It depends , if the first parameter ..\..\states.xml truly refers to an xml file and it is well-formatted, the code could run successfully.

    For example, if   my code is 

       DataSet set = new DataSet();
                set.ReadXml(Server.MapPath("/xmlDemo/dataset.xml"));

    Then I should have dataset.xml in my folder xmlDemo  at root path of my project.

    And below is my xml. song  will be the table name, artist,album,genre .. . will be the column name.

    <music>
                           
                              <song>
                                <artist>Babyface</artist>
                                <genre>RB</genre>
                                <album>Grown and sexy</album>
                                <year>2005</year>
                              </song>
                              <song>
                                <artist>Maria Arredondo</artist>
                                <genre>Pop</genre>
                                <album>Not going under</album>
                                <year>2004</year>
                              </song>
                          
     </music>

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 6, 2019 6:48 AM

All replies

  • User-893317190 posted

    Hi slb2012,

    It depends , if the first parameter ..\..\states.xml truly refers to an xml file and it is well-formatted, the code could run successfully.

    For example, if   my code is 

       DataSet set = new DataSet();
                set.ReadXml(Server.MapPath("/xmlDemo/dataset.xml"));

    Then I should have dataset.xml in my folder xmlDemo  at root path of my project.

    And below is my xml. song  will be the table name, artist,album,genre .. . will be the column name.

    <music>
                           
                              <song>
                                <artist>Babyface</artist>
                                <genre>RB</genre>
                                <album>Grown and sexy</album>
                                <year>2005</year>
                              </song>
                              <song>
                                <artist>Maria Arredondo</artist>
                                <genre>Pop</genre>
                                <album>Not going under</album>
                                <year>2004</year>
                              </song>
                          
     </music>

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 6, 2019 6:48 AM
  • User1077245351 posted

    Thank you for the little orientation you gave me of the XML DataSet path. Yes, if well-formatted, the code could run successfully that is the right answer.  

    Wednesday, March 6, 2019 8:05 AM