Пример #1
0
        private static List <CategoryProduct> get(string query, Dictionary <string, object> parameters)
        {
            CategoryProduct        item = null;
            Connection             cs   = new Connection();
            List <CategoryProduct> list = new List <CategoryProduct>();

            MySqlDataReader reader = cs.Select(query, parameters);

            while (reader.Read())
            {
                item = new CategoryProduct();

                if (!reader.IsDBNull(reader.GetOrdinal("id")))
                {
                    item.id = reader.GetInt32(reader.GetOrdinal("id"));
                }

                if (!(reader["name"] == DBNull.Value))
                {
                    item.name = reader["name"].ToString().Trim();
                }

                if (!(reader["description"] == DBNull.Value))
                {
                    item.description = reader["description"].ToString().Trim();
                }

                list.Add(item);
            }

            cs.CloseConnection();
            return(list);
        }
Пример #2
0
        public static int Add(CategoryProduct m)
        {
            int    t     = 0;
            string query = @"INSERT INTO categoryProduct (name, description) " +
                           "VALUES (@name, @description);";
            Connection cs = new Connection();
            Dictionary <string, object> param = new Dictionary <string, object>();

            param.Add("name", m.name);
            param.Add("description", m.description);

            try
            {
                t = cs.Insert(query, param);
                //si insertion reussit
            }
            catch (MySqlException e) { }
            cs.CloseConnection();
            //si insertion echoue
            return(t);
        }