E_Handel.BL.BLProduct.GetDiscountFromDB C# (CSharp) Method

GetDiscountFromDB() public method

public GetDiscountFromDB ( string databaseConnectionString ) : void
databaseConnectionString string
return void
        public void GetDiscountFromDB(string databaseConnectionString)
        {
            SqlConnection sqlConnection = new SqlConnection(databaseConnectionString);
            SqlCommand sqlGetProduct = new SqlCommand($"SELECT DiscountPercentage FROM DiscountedProducts WHERE ProductID = {Id}", sqlConnection);
            SqlDataReader sqlReader = null;
            Discount = 0;
            try
            {
                sqlConnection.Open();
                sqlReader = sqlGetProduct.ExecuteReader();
                while (sqlReader.Read())
                    Discount = double.Parse(sqlReader["DiscountPercentage"].ToString());
            }
            finally
            {
                if (sqlReader != null)
                {
                    sqlReader.Close();
                    sqlReader.Dispose();
                }
                sqlConnection.Close();
                sqlConnection.Dispose();
                sqlGetProduct.Dispose();
            }
        }
        public void GetTrailerUrlFromDB(string databaseConnectionString)

Usage Example

Beispiel #1
0
 public static BLProduct RetrieveFromDB(string databaseConnectionString, int id)
 {
     SqlConnection sqlConnection = new SqlConnection(databaseConnectionString);
     SqlCommand sqlGetProduct = new SqlCommand($"SELECT CategoryID, Name, Description, Price, Popularity, StockQuantity, VAT FROM Products WHERE ID = {id}", sqlConnection);
     SqlDataReader sqlReader = null;
     try
     {
         sqlConnection.Open();
         sqlReader = sqlGetProduct.ExecuteReader();
         while (sqlReader.Read())
         {
             BLProduct product = new BLProduct(id: id, categoryId: int.Parse(sqlReader["CategoryID"].ToString()),
                 name: sqlReader["Name"].ToString(), description: sqlReader["Description"].ToString(),
                 price: double.Parse(sqlReader["Price"].ToString()),
                 popularity: int.Parse(sqlReader["Popularity"].ToString()),
                 stockQuantity: int.Parse(sqlReader["StockQuantity"].ToString()),
                 VAT: double.Parse(sqlReader["VAT"].ToString()));
             product.GetDiscountFromDB(databaseConnectionString);
             product.GetTrailerUrlFromDB(databaseConnectionString);
             return product;
         }
         return null;
     }
     finally
     {
         if (sqlReader != null)
         {
             sqlReader.Close();
             sqlReader.Dispose();
         }
         sqlConnection.Close();
         sqlConnection.Dispose();
         sqlGetProduct.Dispose();
     }
 }
All Usage Examples Of E_Handel.BL.BLProduct::GetDiscountFromDB