Ejemplo n.º 1
0
        /// <summary>
        /// Get the selected id from the database.
        /// </summary>
        /// <returns>List</returns>
        public List <Adobo> GetById()
        {
            try
            {
                using (MySqlConnection con = new MySqlConnection(AwesomeAdobo.Config.GetConnectionString()))
                {
                    //open connection
                    con.Open();

                    //set query string
                    string sql = "SELECT * FROM adobo WHERE id = @id";

                    //prepare command
                    MySqlCommand cmd = new MySqlCommand(sql, con);

                    //set parameters
                    cmd.Parameters.AddWithValue("id", id);

                    //execute query
                    MySqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Adobo adobo = new Adobo();

                        adobo.id         = int.Parse(reader["id"].ToString());
                        adobo.color      = reader["adobo_color"].ToString();
                        adobo.taste      = reader["adobo_taste"].ToString();
                        adobo.lapotness  = reader["adobo_lapotness"].ToString();
                        adobo.typeOfMeat = reader["adobo_type_of_meat"].ToString();

                        adobos.Add(adobo);
                    }
                }
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }

            return(adobos);
        }
Ejemplo n.º 2
0
        public List<Adobo> Read()
        {
            try
            {
                using (MySqlConnection con = new MySqlConnection(AwesomeAdobo.Config.GetConnectionString()))
                {
                    //open connection
                    con.Open();

                    //set query string
                    string sql = "SELECT * FROM adobo WHERE active = 1";

                    //prepare command
                    MySqlCommand cmd = new MySqlCommand(sql, con);

                    //execute query
                    MySqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Adobo adobo = new Adobo();

                        adobo.id = int.Parse(reader["id"].ToString());
                        adobo.color = reader["adobo_color"].ToString();
                        adobo.taste = reader["adobo_taste"].ToString();
                        adobo.lapotness = reader["adobo_lapotness"].ToString();
                        adobo.typeOfMeat = reader["adobo_type_of_meat"].ToString();

                        adobos.Add(adobo);
                    }
                }
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }

            return adobos;
        }