Posts

Finding Nth Highest Salary Query

SELECT max(sal) FROM  tbltemp WHERE sal NOT IN (SELECT distinct top 2 sal FROM tbltemp ORDER BY sal desc) for eg. for 3rd highest top will be 3-1 =2  (top 2) therefore top N-1 Or SELECT TOP 1 sal  FROM (                SELECT DISTINCT TOP 2 sal                FROM tbltemp               ORDER BY sal DESC               ) A ORDER BY sal

Adding Custom Tags in Web.config

Image
To add cutom tag in your web config its a simple process. I will expain it step by step Add  Following to your web config Remember you have to add information about your System assembly which you can find in your GAC (Global assembly cache) Path: " C:\WINDOWS\assembly " right click on System assembly and you will get Property about it. Then to get those custom tag values  write the following code on default.aspx.cs file  protected void Page_Load(object sender, EventArgs e) {       NameValueCollection Col = new NameValueCollection(); Col = (NameValueCollection)System.Configuration.ConfigurationManager.GetSection("MyCustomSection");         for (int i = 0; i < c1.Keys.Count; i++)         {            Response.Write(String.Format("Key = {0}, Value = {1} ", c1.Keys[i], c1[i].ToString()));   ...

Singleton Design Pattern

one of the good explanation found in ASP.NET 3.5 Application Architecture Design public sealed class EmailManager { private static EmailManager _manager; //Private constructor so that objects cannot be created private EmailManager() { } public static EmailManager GetInstance() { // Use 'Lazy initialization' if (_manager == null) { //ensure thread safety using locks lock(typeof(EmailManager) { _manager = new EmailManager(); } } return _manager; } } let us understand the code step-by-step: 1. public sealed class EmailManager: We have used the sealed keyword to make our EmailManager class uninheritable. This is not necessary, but there is no use having derived classes as there can be only one instance of this class in memory. Having derived class objects will let us create two or more instances which will be against the singleton's design objective. 2. private static EmailManager _manager: Next, we...

SOAP Header (credentials) for cosuming web service

Its the optional part of SOAP Message. Instead including meta data (Credentials) in your web signature you can use SOAP header to consume web service. // SOAP Header class public class HelloHeader : SoapHeader {     public string Username;     public string Password; }     public HelloHeader myHeader;     [WebMethod]     [SoapHeader("myHeader")]     public string HelloWorld()     {         if (myHeader == null)         {             return "Hello World";         }         else         {             return "Hello " + myHeader.Username + ". " +       ...

Metod overloading in web serive

To overload web methods you have to use MessageName attribute otherwise you will get error. [WebMethod(MessageName = "Hello")] public string Hello() { return "Hello"; } [WebMethod(MessageName = "HelloWithFirstName")] public string Hello(string FirstName) { return "Hello " + FirstName; }

Web serice to upload image on server

/// web service /// Upload image on server with the .jpg, .ico, .gif, .bmp, .png formats. /// Size should be less than 80kb /// /// /// /// [WebMethod] public string UploadImage(byte[] ImgIn, string FileName) { MemoryStream ms = null; Bitmap b = null; try { ms = new MemoryStream(ImgIn); if (ms.Length <= 80000) // 80kb limit for image to upload { b = (Bitmap)Image.FromStream(ms); if (FileName.ToLower().Contains(".jpeg") || FileName.ToLower().Contains(".jpg")) b.Save("C:\\" + FileName, System.Drawing.Imaging.ImageFormat.Jpeg); if (FileName.ToLower().Contains(".gif")) b.Save("C:\\" + FileName, System.Drawing.Imaging.ImageFormat.Gif); if (FileName.ToLower().Contains(".bmp")) b.Save("C:\\" + FileName, System.Drawing.Imaging.ImageFormat.Bmp); if (FileName.ToLower().Contains(".png")) b.Save("C:\\" + FileName, System.Drawing.Imaging.ImageFormat.Png); if (FileName.ToLower().Conta...

Nullable in c#

Nullable types can represent all the values of an underlying type, and an additional  null value. Nullable types are declared in one of two ways:         System.Nullable variable         -or-         T? variable     Any value type may be used as the basis for a nullable type  class Program     {         static void Main(string[] args)         {             int? x = 10;             if (x.HasValue)             {                 System.Console.WriteLine(x.Value);           ...