Debug your code and examine the
DataSet
. You will see that the first table only has a single column -
states_Id
. The data you're trying to read is in the
second table.
public List<Products> ReturnListOfProducts()
{
string xmlData = HttpContext.Current.Server.MapPath("~/App_Data/ProductData.xml");
DataSet ds = new DataSet();
ds.ReadXml(xmlData);
return (from rows in ds.Tables[1].AsEnumerable()
select new Products
{
StateName = rows[0].ToString(),
StateId = Convert.ToInt32(rows[1]),
}).ToList();
}
You could have found this out for yourself much faster by using the debugger.