0

here is an example of the xml file:

<Registrerte>
  <Registrert>
    <Kundenavn>Tomas</Kundenavn>
    <Startdato>06.04.2016</Startdato>
    <Antalldager>5</Antalldager>
  </Registrert>
  <Registrert>
    <Kundenavn>Øyvind </Kundenavn>
    <Startdato>08.08.08</Startdato>
    <Antalldager>6</Antalldager>
  </Registrert>
</Registrerte>

here is the code:

DataSet ds = new DataSet(); ds.ReadXml(@"C:\Users\Li\Desktop\oppgave\WebSite4\registrering.xml");

        if (ds.Tables.Count > 0)
        {
            for (int o = 0; o < ds.Tables[0].Rows.Count; o++)
            {
                for (int g = 0; g < ds.Tables[0].Columns.Count; g++)
                {
                    listBox1.Items.Add(ds.Tables[0].Rows[o][g].ToString());
                }
            }
        }

i just want to show Kundenavn in listBox1. how do i do that ?

  • Its quiet unclear what you're asking – Mafii Apr 11 '16 at 11:57
  • Where is the problem? – Hamid Pourjam Apr 11 '16 at 11:58
  • 2
    If you only want to add a specific column, don't loop the columns but only the rows. Use `listBox1.Items.Add(ds.Tables[0].Rows[o][0].ToString());` if you want to add the first column. – Tim Schmelter Apr 11 '16 at 12:03
  • 1
    The 2nd for loop is enumerating through all the columns. To get one column with r use ds.Tables[0].Rows[o][index] or ds.Tables[0].Rows[o][name] where index is the column number and name is the column name. – jdweng Apr 11 '16 at 12:08

0 Answers0