예제 #1
0
        public static ListMaker Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();

            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM `items` WHERE id = @thisId;";

            MySqlParameter thisId = new MySqlParameter();

            thisId.ParameterName = "@thisId";
            thisId.Value         = id;
            cmd.Parameters.Add(thisId);

            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            int    itemId          = 0;
            string itemDescription = "";

            while (rdr.Read())
            {
                itemId          = rdr.GetInt32(0);
                itemDescription = rdr.GetString(1);
            }

            ListMaker foundItem = new ListMaker(itemDescription, itemId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }

            return(foundItem);
        }
예제 #2
0
        public List <ListMaker> GetItems()
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT items.* FROM categories
                JOIN categories_items ON (categories.id = categories_items.category_id)
                JOIN items ON (categories_items.item_id = items.id)
                WHERE categories.id = @CategoryId;";

            MySqlParameter categoryIdParameter = new MySqlParameter();

            categoryIdParameter.ParameterName = "@CategoryId";
            categoryIdParameter.Value         = _id;
            cmd.Parameters.Add(categoryIdParameter);

            MySqlDataReader  rdr   = cmd.ExecuteReader() as MySqlDataReader;
            List <ListMaker> items = new List <ListMaker> {
            };

            while (rdr.Read())
            {
                int       itemId          = rdr.GetInt32(0);
                string    itemDescription = rdr.GetString(1);
                ListMaker newItem         = new ListMaker(itemDescription, itemId);
                items.Add(newItem);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(items);
        }