public static Item Find(int id) { int itemId = -1; string itemDescription = ""; DateTime date = new DateTime(0); DB.OpenConnection(); DB.SetCommand(@"SELECT * FROM items WHERE id=@thisId;"); DB.AddParameter("@thisId", id); MySqlDataReader rdr = DB.ReadSqlCommand(); while (rdr.Read()) { itemId = rdr.GetInt32(0); itemDescription = rdr.GetString(1); date = rdr.GetDateTime(2); } DB.CloseConnection(); return(new Item(itemDescription, date, itemId)); }
public List <Item> GetAllItems(string tableName, string orderBy = "id", string order = "ASC") { List <Item> allItems = new List <Item> { }; DB.OpenConnection(); DB.SetCommand(@"SELECT * FROM items WHERE category_id=@id ORDER BY " + orderBy + " " + order + ";"); DB.AddParameter("@id", _id); MySqlDataReader rdr = DB.ReadSqlCommand(); while (rdr.Read()) { int itemId = rdr.GetInt32(0); string itemDescription = rdr.GetString(1); DateTime date = rdr.GetDateTime(2); Item newItem = new Item(itemDescription, date, itemId); allItems.Add(newItem); } DB.CloseConnection(); _itemList = allItems; return(_itemList); }