Hello all,
I have an xml file with the information below:
<?xml version="1.0" encoding="utf-8" ?>
<ServerNames>
<Name>dfwnbonner1</Name>
</ServerNames>
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()
{
InitializeComponent();
this.WindowState = FormWindowState.Maximized;
FillList();
}
public static DataTable GetServers()
{
DataSet dsStore = new DataSet();
dsStore.ReadXml("config.xml");
// Test the count of tables and a relation
//MessageBox.Show(dsStore.Tables.Count + " " + dsStore.Relations[0].RelationName);
return dsStore.Tables["ServerNames"];
}
private void FillList()
{
serverList.Items.Clear();
DataTable dtServers = GetServers();
serverList.BeginUpdate();
foreach (DataRow dr in dtServers.Rows)
{
ListViewItem listItem = new ListViewItem(dr["Name"].ToString());
string serverStatus = ReturnStatus(dr["Name"].ToString());
if (serverStatus == "Online")
{
listItem.SubItems.Add(NetworkDiscovery.GetIPAddress(dr["Name"].ToString()));
}
else
listItem.SubItems.Add("0.0.0.0");
listItem.SubItems.Add(ReturnStatus(dr["Name"].ToString()));
listItem.ImageIndex = 0;
serverList.Items.Add(listItem);
}
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);
}
serverList.EndUpdate();
}
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.