Posts

Showing posts from September, 2009

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 + ". " +             " Your password is: " + myHeader.Password;         }     } // Consuming this web service localhost.HelloHeader objHEader = new WindowsApplication1.localhost.HelloHeader(); localhost.HelloSoapHeader objService = new WindowsApplication1.localhost.HelloSoapHeader(); objHEader.Username = "milind"; objHEader.Password = "mahajan"; objServic

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);             }             else             {                 System.Console.WriteLine("Undefined");             }             Console.ReadKey();             int? y = null;             if (y != null)             {                 System.Console.WriteLine(y.Value);             }             else             {                 System.Console.WriteLine("Undefined");             }             Console.ReadKey();             int? n = 5;             //int m1 = n;      // Will not co

Explicit keyword in c#

The explicit keyword is used to declare an explicit user-defined type conversion operator  class Celsius     {         public Celsius(float temp)         {             degrees = temp;         } // define explicit Celsius-to-Fahrenheit conversion operator:         public static explicit operator Fahrenheit(Celsius c)         {             return new Fahrenheit((9.0f / 5.0f) * c.degrees + 32);         }         public float Degrees         {             get { return degrees; }         }         private float degrees;     }     class Fahrenheit     {         public Fahrenheit(float temp)         {             degrees = temp;         } // define explicit Fahrenheit-to-Celsius conversion operator:         public static explicit operator Celsius(Fahrenheit f)         {             return new Celsius((5.0f / 9.0f) * (f.degrees - 32));         }         public float Degrees         {             get { return degrees; }         }         private float degrees;

Cursor in sql server

-To fetch row by row data Declare Cursor Open Fetch first time fetch data until @@Fetch_Status = 0 Close Deallocate Disadvantage: - Time Consuming - required lot of resources & temporary storage.

View in sql server

Referred as "Virtual Table" Can not store data (except for indexed views) rather than only referto data present in table. e.g. Create View vwsample [optional] With Encryption OR With Schemabinding [/optional] AS Select Cid, CName FRom Customer GO With Encryption - You can see view query (its encrypted) With Schemabinding - You are not able to alter table on which it's created.

Assembly in .net

Image
-It is the fundamental building block of .net framework -basic unit of deployment or versioning (.exe or .dll) -Consisting Manifest Metadata IL Code Resources 1) Manifest- Describe assembly itself Contents Assembly Name Version number Culture Strong name information List of files Type reference information Information on reference assemblies 2) Metdata- Describe Contents within assembly like Classes, Namespaces, Interfaces, Scope, Properties, Methods & their parameteres. 3) IL Code- The compilers translates your code into Microsoft intermediate language (MSIL). The common language runtime includes a JIT compiler for converting this MSIL then to native code. 4) Resources- are the files like image files

Command Object's Method

objects exposes methods for executing commands based on the type of command and desired return value 1) ExecuteNonQuery: Executes a command that does not return any rows. 2) ExecuteReader: Returns a DataReader object. 3) ExecuteRow: Return sql record (return one datbase record) 4) ExecuteScalar: Returns a single scalar value. 5) ExecuteXMLReader: Returns an XmlReader. Available for a SqlCommand object only.

Triggers in sql server

Definition: Are special type of stored procedure that are defined to execute automatically, In place of or after data modification when Insert, Update, Delete triggering actions occurred on that table. 1) After Trigger Fired the triggering action. Executed automatically before the transaction is committed or rolled back. e.g. CREATE TRIGGER trgCheckStock ON [products] FOR UPDATE AS IF( Select inStockFrom inserted ) < 0) BEGIN PRINT 'Can not oversell products' PRINT 'Transaction has been canceled' END GO 2) Instead Of Trigger Fire in place of the triggering action. Executed automatically before primary key and foreign key constraints are checked. e.g. CREATE TRIGGER trgCantDelete ON table1 INSTEAD OF DELETE AS PRINT 'you cannot delete this data' GO

Resume

Latest Resume - Upload a Document to Scribd Read this document on Scribd: Latest Resume

Differance between Value Type and Referance Type

Value Type: 1) Stored in stack. 2) Access directly. 3) Life time determine by lifetime of variable that contain them. 4) e.g. All numeric data type, Boolean, char, Date, Structure, enumerations. Reference Type: 1) Stored in heap. 2) Access through references. 3) Lifetime is managed by .net framework. 4) e.g. All arrays, String, Class types, Delegate. Note: Object is not any kind of type. You can create object of structure as well as Class Are not type: Namespaces, Modules, Events, properties, procedures, variables, constants ,& fields.

Differance between Dataset and Datareader

Dataset 1) Read/write access to data. 2) Disconnected architecture. 3) Include multiple table from different database. 4) Bind to multiple controls. 5) forward and backward scanning of data. 6) supported by visual studio .net tool. 7) you can set relation between tables. DataReader 1) Read only 2) Connected architecture. 3) Include 1 table from 1 database only. 4) Bind to one control only. 5) fast forward only. 6) Manually coded. 7) No relations.

Differance between Strucutre and Class

Structure: 1) Value type stored in stack. 2) Inheritance is not possible in structure. 3) do not require constructor. 4) objects are not terminated by GC. 5) members can not be protected. Class: 1) Reference type stored in heap. 2) Inheritance is possible. 3) Contain constructor. 4) object is terminated by GC. 3) Member can be any type.

Differeance between Interface and Abstract Class

Interface: 1) Define a Contract. 2) can inherit only interfaces. 3) don't have constructor and distructor. 4) don't have concrete methods. 5) Inheritable by Structure. 6) Multiple inheritance is possible using Interface. 7) All members are Public by default. Abstract Class: 1) Can't be initiated, partially implemented. 2) Can inherit classes & Interfaces. 3) Can have Constructor & Distructor. 4) Some methods can be concrete. 5) Not inheritable by structure. 6) Multiple inheritance not possible. 7) Members can have many modifiers.

Differance between Overloading and Overriding

Overloading: 1) Same name in same/derived class but with different/type of parameter. 2) Compiletime polymorphism. 3) Having Different signature. Overriding: 1) we need to provide different implementation than base class. 2) Runtime Polymorphism. 3) Having same signature.

Differance between Const and Readonly

Const 1) Value evaluated at compile time 2) can't be static. 3) Initialize at declaration only. e.g. const int a = 100 Readonly 1) Value evaluated at runtime. 2) Can be static. 3) can initialize at declaration or in constructor. e.g. public readonly int doc = 5; public program() { doc = 5; }

Differance between Truncate and Delete

Truncate 1) Delete all rows. 2) Identity counter reset. 3) Don't make entry to transaction log. therefore it is faster. 4) DDL command. 5) can not rollback 6) do not activate trigger. Delete 1) Delete 1 or more row depend on where clause. 2) retain Identity counter. 3) Make entery to transaction log. so it is slower. 4) DML command. 5) Can be rollback. 6) Activate trigger.