Hello all,

I have an xml file with the information below:

<?xml version="1.0" encoding="utf-8" ?>

I am trying to get the Name of a server into a listview. This works fine with the above xml but as soon as I add another server name in <Name></Name> it crashes. This is killing me and I have been looking at it for hours. Here is my code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using FX.Network.Utility;

namespace CMC_QA_Env
    public partial class ViewServers : Form
        public ViewServers()
            this.WindowState = FormWindowState.Maximized;


    public static  DataTable GetServers()
        DataSet dsStore = new DataSet();
        // Test the count of tables and a relation
        //MessageBox.Show(dsStore.Tables.Count + "  "  +  dsStore.Relations[0].RelationName);
        return dsStore.Tables["ServerNames"];

    private void FillList()
            DataTable dtServers = GetServers();

            foreach (DataRow dr in dtServers.Rows)
                ListViewItem listItem = new ListViewItem(dr["Name"].ToString());
                string serverStatus = ReturnStatus(dr["Name"].ToString());

                if (serverStatus == "Online")


                listItem.ImageIndex = 0;

            if (serverList.Columns.Count == 0)
                serverList.Columns.Add("Server Name", 150, HorizontalAlignment.Left);
                serverList.Columns.Add("IP Address", 100, HorizontalAlignment.Left);
                serverList.Columns.Add("Status", 100, HorizontalAlignment.Left);


Like I said, it displays everything fine with 1 server listed in the XML file but as soon as I add another it crashes at the line: return dsStore.Tables["ServerNames"];

Also if I uncomment

MessageBox.Show(dsStore.Tables.Count + "  "  +  dsStore.Relations[0].RelationName);

It crashe with both 1 and 1+ servernames.

THANKS for anyone that can assist.

Hey guys. I found out my problem. My XML was not in the correct format. Changed to This

<?xml version="1.0" encoding="utf-8" ?>

and changed the reference here:

return dsStore.Tables["server"];    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.