public void RefreshList() { AnimalList = new List<Animal>(); DataSet data = StoreInfo.sharedStoreInfo().LoadTable("animalrecords_tb"); foreach (DataTable table in data.Tables) { foreach (DataRow row in table.Rows) { int id = Convert.ToInt32(row.ItemArray[0].ToString()); string name = row.ItemArray[1].ToString(); Animal animal = new Animal(id, name); AnimalList.Add(animal); } } }
public List<Animal> ShowInventory() { List<Animal> animalList = new List<Animal>(); MySqlConnection connection = new MySqlConnection(myConnectionString); connection.Open(); try { MySqlCommand cmd = connection.CreateCommand(); cmd.CommandText = "SELECT ID_animalrecord, ID_animal FROM animal_tb WHERE ID_cage='" + Id + "'"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); foreach (DataTable table in ds.Tables) { foreach (DataRow row in table.Rows) { System.Diagnostics.Debug.WriteLine(row.ItemArray[0].ToString() + "def"); int id = Convert.ToInt32(row.ItemArray[0].ToString()); int orderId = Convert.ToInt32(row.ItemArray[1].ToString()); System.Diagnostics.Debug.WriteLine(id + "SdSADSAD"); System.Diagnostics.Debug.WriteLine(orderId + "DSADASDSA"); Animal animal = new Animal(id, orderId); animalList.Add(animal); } } return animalList; } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); throw; } finally { if (connection.State == ConnectionState.Open) { connection.Close(); } } }