Sunday, 11 September 2016

--Query to find ties between rating of 2 products with "ties"---

The below query explains how to find a tie between rating of 2 products. For example out of given 5 product rating on an ecommerce web site you need to find the top 2 rating prodcuts(brand) what if 2 products(brands) have same rating and are equally placed in 2nd position? Use the below query to solve the problem.

create table product-- Create a table product with brand,rating and price as variables--
(brand varchar(50),rating int,price int)

select * from product

Out put// You will get the output as shown below//







Insert the number of values(5 in this case) required in the table 

-- after inserting the values to find the top2 rating use the below query--

select * from product


select top 2 with ties * from product  -- using ties here gives you 3 values even if you are lo0king for only 2 values with higher rating as rating of brands are equal for 2n and 3rd// if you do not use tie you will get only 2 values--
where brand in (rating>=1)
order by rating asc-- this orders brands in ascending order as per the ratings--








Wednesday, 9 April 2014

Use of log4net Logging Mechanism in C#

DLL Used : log4Net 1.2.13

App.Config File Settings
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
  </configSections>

  <!--<log4net.dll Configuration Settings Date : 09/04/2013>-->
  <log4net>
    <!--<Appender for Info and Error logging>-->
    <appender name="LogInfoFileAppender" type="log4net.Appender.RollingFileAppender">
      <param name="File" value="D:\\StudentDataLog.txt"/>
      <!--<Please specify the file with path here for log file>-->
      <param name="AppendToFile" value="true"/>
      <rollingStyle value="Size"/>
      <maxSizeRollBackups value="2"/>
      <maximumFileSize value="10MB"/>
      <staticLogFileName value="true"/>
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%-5p – %20C %20M %m%n%n"/>
      </layout>
    </appender>

    <root>
      <level value="ALL"/>
      <appender-ref ref="LogInfoFileAppender"/>
    </root>


  </log4net>
</configuration>

In cs file
using log4net.Layout;
using log4net;

private static readonly ILog _log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);


public StudentInformation()
{
    InitializeComponent();
    log4net.Config.XmlConfigurator.Configure();
}

public void SaveInformation()
{
   log.Info("Revanayya Hiremath");
   log.Info("2BA10MCA15");
   log.Info("Mahesh Datta");
   log.Info("084GE08CS020);
}

Possible Errors while running in VS 2010
The namespace or namespace name 'log4net' could not be found
If you have added a reference to log4net correctly and added your usings, you may get a compile error “The type or namespace name ‘log4net’ could not be found (are you missing a using directive or an assembly reference?)”.


This is most likely due to the Target framework being set to .NET Framework X Client Profile. Change this to .NET Framwork 4 (full version) and your application will compile.




IsDebugEnabled, IsErrorEnabled, IsFatalEnabled is flase

Before:


After:    
Use below code before writing the log  

log4net.Config.XmlConfigurator.Configure()