Exemple #1
0
        public List <ContainsDetails> dbGetContains(int IdRecepta)
        {
            if (con.State != System.Data.ConnectionState.Open)
            {
                con.Open();
            }
            List <ContainsDetails> listContainsDetails = new List <ContainsDetails>();
            SqlCommand             cmd = new SqlCommand("SELECT * FROM [Contain] INNER JOIN [Groceries] ON Contain.GroceryName=Groceries.Name WHERE RecipeID=@ID", con);

            cmd.Parameters.Add("@ID", SqlDbType.Int).Value = IdRecepta;
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                ContainsDetails contains = new ContainsDetails();
                GroceryDetails  grocery  = new GroceryDetails();
                contains.Amount   = float.Parse(reader.GetValue(2).ToString());
                contains.RecipeID = int.Parse(reader.GetValue(1).ToString());
                grocery.Image     = null;
                grocery.Name      = reader.GetValue(3).ToString();
                grocery.Unit      = reader.GetValue(5).ToString();
                grocery.Category  = reader.GetValue(6).ToString();
                contains.Grocery  = grocery;
                listContainsDetails.Add(contains);
            }
            reader.Close();
            cmd.Dispose();
            con.Close();
            return(listContainsDetails);
        }
Exemple #2
0
        public void loadContains(ContainsDetails contains)
        {
            if (con.State != System.Data.ConnectionState.Open)
            {
                con.Open();
            }
            SqlCommand cmd = new SqlCommand("INSERT into [Contain](RecipeID,GroceryName,Amount) VALUES(@ID,@Name,@Amount)", con);

            cmd.Parameters.Add("@ID", System.Data.SqlDbType.VarChar).Value     = contains.RecipeID;
            cmd.Parameters.Add("@Name", System.Data.SqlDbType.VarChar).Value   = contains.Grocery.Name;
            cmd.Parameters.Add("@Amount", System.Data.SqlDbType.VarChar).Value = contains.Amount;
            int test = cmd.ExecuteNonQuery();

            cmd.Dispose();
            con.Close();
        }