Monday 24 December 2012

what a trcik must check

http://blog.sqlauthority.com/2012/12/19/sql-server-select-and-delete-duplicate-records-sql-in-sixty-seconds-036-video/

Thursday 20 December 2012

hashtable in asp.net c#

The Hashtable object contains items in key/value pairs. The keys are used as indexes, and very quick searches can be made for values by searching through their keys.



Hashtable hashtable = new Hashtable();
key = 1;
name = "A";
hashtable.Add(key,name);
key = 2;
name = "B";
hashtable.Add(key,name);
key = 3;
name = "lily";
hashtable.Add(key,name);



u can use foreach loop for read 

foreach (string key in hashtable.Keys)   {     
    Response.Write(key + '=' + hashtable[key] + "<br>");   
}

Friday 14 December 2012

Sealed Classes in c# , .Net


Sealed classes are used to restrict the inheritance feature of object oriented programming. Once a class is defined as sealed class, this class cannot be inherited. 
In C#, the sealed modifier is used to define a class as sealed. In Visual Basic .NET,NotInheritable keyword serves the purpose of sealed. If a class is derived from a sealed class, compiler throws an error. 
If you have ever noticed, structs are sealed. You cannot derive a class from a struct.  

The following class definition defines a sealed class in C#: 
// Sealed class
sealed class SealedClass
{
    } 

In the following code, I create a sealed class SealedClass and use it from Class1. If you run this code, it will work fine. But if you try to derive a class from sealed class, you will get an error.
 

using System;
class Class1
{
    static void Main(string[] args)
    {
        SealedClass sealedCls = new SealedClass();
        int total = sealedCls.Add(45);
        Console.WriteLine("Total = " + total.ToString());
    }
}
// Sealed class
sealed class SealedClass
{
    public int Add(int x, int y)
    {
        return x + y;
    }
}  


Why Sealed Classes?
 

We just saw how to create and use a sealed class. The main purpose of a sealed class to take away the inheritance feature from the user so they cannot derive a class from a sealed class. One of the best usage of sealed classes is when you have a class with static members. For example, the Pens and Brushes classes of the System.Drawingnamespace. 
The Pens class represent the pens for standard colors. This class has only static members. For example, Pens.Blue represents a pen with blue color. Similarly, the Brushes class represents standard brushes. The Brushes.Blue represents a brush with blue color. 
So when you're designing your application, you may keep in mind that you have sealed classes to seal user's boundaries. 
In the next article of this series, I will discuss some usage of abstract classes. 

Wednesday 12 December 2012

Http Handler and http Modules



ASP.NET handles all the HTTP requests coming from the user and generates the appropriate response for it. ASP.NET framework knows how to process different kind of requests based on extension, for example, It can handle request for.aspx.ascx and .txt files, etc. When it receives any request, it checks the extension to see if it can handle that request and performs some predefined steps to serve that request.

Now as a developer, we might want to have some of our own functionality plugged in. We might want to handle some new kind of requests or perhaps we want to handle an existing request ourselves to have more control on the generated response, for example, we may want to decide how the request for .jpg or .gif files will be handled. Here, we will need anHTTPHandler to have our functionality in place.
There are also some scenarios where we are ok with the way ASP.NET is handling the requests but we want to perform some additional tasks on each request, i.e., we want to have our tasks execute along with the predefined steps ASP.NET is taking on each request. If we want to do this, we can have HTTPModule in place to achieve that.
So from the above discussion, it is clear that HTTPHandlers are used by ASP.NET to handle the specific requests based on extensions. HTTPModule, on the other hand, is used if we want to have our own functionality working along with the default ASP.NET functionality. There is one Handler for a specific request but there could be N number of modules for that.


For more detail visit 
Click here

Union and Union All


UNION
The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type. With UNION, only distinct values are selected.
UNION ALL
The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values.
The difference between Union and Union all is that Union all will not eliminate duplicate rows, instead it just pulls all rows from all tables fitting your query specifics and combines them into a table.

Tuesday 11 December 2012

Magic tables In sql server

Magic tables are nothing but INSERTED, DELETED table scope level, These are not physical tables, only Internal tables. 

This Magic table are used In SQL Server 6.5, 7.0 & 2000 versions with Triggers only. 

But, In SQL Server 2005, 2008 & 2008 R2 Versions can use these Magic tables with Triggers and Non-Triggers also. 

Using with Triggers: 
If you have implemented any trigger for any Tables then, 
1.Whenever you Insert a record on that table, That record will be there on INSERTED Magic table. 
2.Whenever you Update the record on that table, That existing record will be there on DELETED Magic table and modified New data with be there in INSERTED Magic table. 
3.Whenever you Delete the record on that table, That record will be there on DELETED Magic table Only. 

These magic table are used inside the Triggers for tracking the data transaction. 

Using Non-Triggers: 
You can also use the Magic tables with Non-Trigger activities using OUTPUT Clause in SQL Server 2005, 2008 & 2008 R2 versions. 

Common Language Runtime (CLR)


The .NET Framework provides a run-time environment called the common language runtime, which runs the code and provides services that make the development process easier.
Compilers and tools expose the common language runtime's functionality and enable you to write code that benefits from this managed execution environment. Code that you develop with a language compiler that targets the runtime is called managed code; it benefits from features such as cross-language integration, cross-language exception handling, enhanced security, versioning and deployment support, a simplified model for component interaction, and debugging and profiling services.

Friday 7 December 2012

Cord first entity framwork

try the link for learn in breif 

http://msdn.microsoft.com/en-us/data/gg685467.aspx

Interface in c#


Interfaces in C# (For Beginners)

Introduction
Interfaces in C # provide a way to achieve runtime polymorphism. Using interfaces we can invoke functions from different classes through the same Interface reference, whereas using virtual functions we can invoke functions from different classes in the same inheritance hierarchy through the same reference. Before things start getting difficult let me start using simple and short examples to explain the concept of interfaces. Here's a short example that shows you what an interface looks like.

P1.cs

 Collapse | Copy Code
class Demo
{
  public static void Main()
  {
    System.Console.WriteLine("Hello Interfaces");
  }
}
 
interface abc
}

Output

 Collapse | Copy Code
Hello Interfaces
The above program compiles and runs successfully to produce the desired output. The above program consists of a classDemo and within it an entry point function Main() that prints Hello Interfaces. The above program also defines an interface abc. Interface abc is empty at this point of time. Let's add some elements to this interface.

P2.cs

 Collapse | Copy Code
class Demo
{
  public static void Main()
  {
    System.Console.WriteLine("Hello Interfaces");
  }
}
 
interface abc
{
  int x;  
}

Output

 Collapse | Copy Code
P2.cs(11,3): error CS0525: Interfaces cannot contain fields
Error! Interfaces in C# cannot contain fields i.e variables. The above program declared an integer variable x in the interface abc. And that's what hit the C# compiler badly.

P3.cs

 Collapse | Copy Code
class Demo
{
  public static void Main()
  {
    System.Console.WriteLine("Hello Interfaces");
  }
}
 
interface abc
{
  void xyz()
  {
     System.Console.WriteLine("In xyz");
  }  
}

Output

 Collapse | Copy Code
P3.cs(11,8): error CS0531: 'abc.xyz()': interface members cannot have a 
    definition
This time over we included a function xyz() inside the interface found that this too hurt the C# compiler. It told us loudly that interface members cannot have a defination. Does this mean that if we just have a function declaration inside the interface abc that is fine with the C# compiler? Let's find it out.

P4.cs

 Collapse | Copy Code
class Demo
{
  public static void Main()
  {
    System.Console.WriteLine("Hello Interfaces");
  }
}
 
interface abc
{
  void xyz();
}

Output

 Collapse | Copy Code
Hello Interfaces
The above program compiles and runs successfully to produce the desired output. Finally we made the compiler happy. Interfaces in C# can only contain function declarations. Now let us see interfaces in action.
Interfaces are contracts that a class implements in its own way. This means an interface will contain function prototypes and a class that marries this interface will have to take the responsibility of defining the functions whose prototypes are declared by the marrying interface.
So its time to perform the marriage between our groom class Demo and the bride interface abc.

P4.cs

 Collapse | Copy Code
class Demo : abc
{
  public static void Main()
  {
    System.Console.WriteLine("Hello Interfaces");
  }
}
 
interface abc
{
  void xyz();
}

Output

 Collapse | Copy Code
P4.cs(1,7): error CS0535: 'Demo' does not implement interface member 
    'abc.xyz()'
P4.cs(11,8): (Location of symbol related to previous error)
Well, in the above program class Demo did marry the interface abc through the line class demo : abc but as usual there's a small misunderstanding between the newlyweds. Class Demo needs to take the responsibility of defining the functions whose prototypes are declared by the marrying interface abc. Since class Demo in the above program has not been implemented i.e. defined the function xyz whose prototype is declared by the marrying interface abc we get an error in the above program. To fix this issue, the class Demo has to take the responsiility of defining the function xyzwhose prototype is declared by the marrying interface abc. And that is what you get to see in the following program.

P5.cs

 Collapse | Copy Code
class Demo : abc
{
  public static void Main()
  {
    System.Console.WriteLine("Hello Interfaces");
  }
 
  void xyz()
  {
     System.Console.WriteLine("In xyz");
  }  
}
 
interface abc
{
  void xyz();
}

Output

 Collapse | Copy Code
a.cs(1,7): error CS0536: 'Demo' does not implement interface member 
    'abc.xyz()'.'Demo.xyz()' is either static, not public, 
    or has  the wrong return type.
a.cs(16,8): (Location of symbol related to previous error)
a.cs(7,8): (Location of symbol related to previous error)
Error again! It's not enough for the class Demo to implement the function xyz. It has to impress the bride interface abc by declaring its implementation of xyz as public. And that's what is done by the following program.

P6.cs

 Collapse | Copy Code
class Demo : abc
{
  public static void Main()
  {
    System.Console.WriteLine("Hello Interfaces");
    xyz();
  }
 
  public void xyz()
  {
     System.Console.WriteLine("In xyz");
  }  
}
 
interface abc
{
  void xyz();
}

Output

 Collapse | Copy Code
Hello Interfaces
In xyz
Bingo! The above program compiles and runs successfully to produce the desired output. As mentioned earlier using interfaces we can invoke functions from different classes using the same interface reference. For this, we need to have different classes to implement the same interface. In the above program our class Demo is implementing the interfaceabc. Let's have another class Sample that implements the interface abc.

P7.cs

 Collapse | Copy Code
class Demo : abc
{
  public static void Main()
  {
    System.Console.WriteLine("Hello Interfaces");
    Demo refDemo = new Demo();
    refDemo.xyz();
    Sample refSample = new Sample();
    refSample.xyz();    
  }
 
  public void xyz()
  {
     System.Console.WriteLine("In Demo :: xyz");
  }  
}
 
interface abc
{
  void xyz();
}
 
class Sample : abc
{
  public void xyz()
  {
     System.Console.WriteLine("In Sample :: xyz");
  }  
}

Output

 Collapse | Copy Code
In Demo :: xyz
In Sample :: xyz
The above program compiles and runs successfully to produce the desired output. refDemo is a reference to the object of class Demo. refSample is a reference to the object of class Sample. Both the classes implement the interface abcand hence define their own implementation of the function xyz(). From within the entry point function Main() xyz()of the respective classes Demo and Sample are invoked through references refDemo and refSample.
Now that we have two different classes implementing the same interface its time to show you how to invoke functions from different classes using the same interface reference.

P8.cs

 Collapse | Copy Code
class Demo : abc
{
  public static void Main()
  {
    System.Console.WriteLine("Hello Interfaces");
    abc refabc = new Demo();
    refabc.xyz();
    abc refabc = new Sample();
    refabc.xyz();    
  }
 
  public void xyz()
  {
     System.Console.WriteLine("In Demo :: xyz");
  }  
}
 
interface abc
{
  void xyz();
}
 
class Sample : abc
{
  public void xyz()
  {
     System.Console.WriteLine("In Sample :: xyz");
  }  
}

Output

 Collapse | Copy Code
In Demo :: xyz
In Sample :: xyz
The above program compiles and runs successfully to produce the desired output. Inside Main() we have an interface reference refabc of type interface abc. Reference of object of class Demo is stored in refabc and xyz() of classDemo is invoked using refabc. Next, the reference of object of class Sample is stored in refabc and xyz() of classSample is invoked using refabc. Thus, we were able to invoke xyz() that belongs to different classes Demo andSample via a common interface reference refabc.
The following program uses a for loop to invoke the functions of different classes Demo and Sample that implement the same interface "interface abc" using a single interface reference refabc whose type matches the interface "interface abc" which the classes impliment.

P9.cs

 Collapse | Copy Code
class Demo : abc
{
  public static void Main()
  {
    abc [] refabc = {new Demo(), new Sample()} ;
    for (int i = 0; i<= 1; i++)
      refabc[i].xyz();
  }
 
  public void xyz()
  {
     System.Console.WriteLine("In Demo :: xyz");
  }  
}
 
interface abc
{
  void xyz();
}
 
class Sample : abc
{
  public void xyz()
  {
     System.Console.WriteLine("In Sample :: xyz");
  }  
}

Output

 Collapse | Copy Code
In Demo :: xyz
In Sample :: xyz
The above program compiles and runs successfully to produce the desired output. refabc is an array of type interfaceabc. It stores the references to objects of classes Demo and Sample. In the for loop, using the array refabc, we are invoking the function xyz() of class Demo and Sample. A class can impliment as many interfaces as it wants. Take the following program.

P10.cs

 Collapse | Copy Code
class Demo : abc, def
{
  public static void Main()
  {
    System.Console.WriteLine("Hello Interfaces");
    abc refabc = new Demo();
    refabc.xyz();
  }
 
  public void xyz()
  {
     System.Console.WriteLine("In xyz");
  }  
 
  public void pqr()
  {
     System.Console.WriteLine("In xyz");
  }
}
 
interface abc
{
  void xyz();
}
 
interface def
{
  void pqr();
}

Output

 Collapse | Copy Code
Hello Interfaces
In xyz
The above program compiles and runs successfully to produce a desired output. Class Demo implements interface abcand thereby function xyz(). Class Demo also impliments interface def and thereby function pqr(). ref abc which is a variable of type Interface abc, refers to object of class Demo. Next xyz() of Demo is invoked via refabc as refabc is a variable of type Interface abc which contains the prototype for function xyz().