public void Create(Product entity)
        {
            using (SqlConnection connection = conn.OpenConnection())
            {
                using (SqlCommand cmd = connection.CreateCommand())
                {
                    cmd.CommandText = "Insert into ProductDB (Name, Price, Description, Stock, Sold ) values (@Name, @Price, @Description, @Stock, @Sold)";
                    cmd.Parameters.AddWithValue("Name", entity.Name);
                    cmd.Parameters.AddWithValue("Price", entity.Price);
                    cmd.Parameters.AddWithValue("Description", entity.Description);
                    cmd.Parameters.AddWithValue("Stock", entity.Stock);
                    cmd.Parameters.AddWithValue("Sold", entity.Sold);
                    cmd.ExecuteNonQuery();
                }

                connection.Close();
            }
        }
Beispiel #2
0
 public void Create(Customer entity)
 {
     using (SqlConnection connection = conn.OpenConnection())
     {
         using (SqlCommand cmd = connection.CreateCommand())
         {
             cmd.CommandText = "Insert into CustomerDB (Phone, FName, LName, City, ZipCode, Email, CVR, CustomerType) values (@Phone, @FName, @LName, @City, @ZipCode, @Email, @CVR, @CustomerType)";
             cmd.Parameters.AddWithValue("Phone", entity.Phone);
             cmd.Parameters.AddWithValue("FName", entity.FName);
             cmd.Parameters.AddWithValue("LName", entity.LName);
             cmd.Parameters.AddWithValue("City", entity.City);
             cmd.Parameters.AddWithValue("ZipCode", entity.ZipCode);
             cmd.Parameters.AddWithValue("Email", entity.Email);
             cmd.Parameters.AddWithValue("CVR", entity.CVR);
             cmd.Parameters.AddWithValue("CustomerType", entity.CustomerType);
             cmd.ExecuteNonQuery();
         }
         connection.Close();
     }
 }