Pages

Thursday, 26 April 2012

LINQ in ASP .Net


LINQ quries :


protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        Dataset dataContext = 
            new Dataset();
       //bind tables or data source in dataset
        var query = from contact in dataContext.tablename
          where tablename.columnname==1
          select contact;

        GridView1.DataSource = query;
        GridView1.DataBind();
    }
}

For more detail.....click here..........

Thursday, 19 April 2012

Get IP Address of current system



Get IP Address :


string ip_address = HttpContext.Current.Request.UserHostAddress.ToString();

***************************************************

get host name :


string hostName = System.Net.Dns.GetHostName();



Friday, 13 April 2012

Create the session in ASP .Net


//Create the session 


Session["Name"] = "Rohit Prakash";
//orSession.Add("Name","Rahul");

//retrieving the session any where in the application/page

string Name = (string)Session["Name"];


Off - No session state will be stored
InProc - (The Default) Session state exists within the process the web is using
StateServer - Session data is sent to the configured stateserver service
SQLServer - Session data is store in the configured sql server database


Wednesday, 11 April 2012

Introduction of LINQ in ASP .Net


Language-Integrated Query (LINQ)


Language-Integrated Query (LINQ) is an innovation introduced in Visual Studio 2008 and .NET Framework version 3.5 that bridges the gap between the world of objects and the world of data.
Traditionally, queries against data are expressed as simple strings without type checking at compile time or IntelliSense support. Furthermore, you have to learn a different query language for each type of data source: SQL databases, XML documents, various Web services, and so on. LINQ makes a query a first-class language construct in C# and Visual Basic. You write queries against strongly typed collections of objects by using language keywords and familiar operators. The following illustration shows a partially-completed LINQ query against a SQL Server database in C# with full type checking and IntelliSense support.





LINQ query with Intellisense





In Visual Studio you can write LINQ queries in Visual Basic or C# with SQL Server databases, XML documents, ADO.NET Datasets, and any collection of objects that supportsIEnumerable or the generic IEnumerable<T> interface. LINQ support for the ADO.NET Entity Framework is also planned, and LINQ providers are being written by third parties for many Web services and other database implementations.

Saturday, 21 January 2012

Difference between Abstract class and Interface in C# .Net


Difference between Abstract class and Interface in C# .Net



What is an Abstract Class?


An abstract class is a special kind of class that cannot be instantiated. So the question is why we need a class that cannot be instantiated? An abstract class is only to be sub-classed (inherited from). In other words, it only allows other classes to inherit from it but cannot be instantiated. The advantage is that it enforces certain hierarchies for all the subclasses. In simple words, it is a kind of contract that forces all the subclasses to carry on the same hierarchies or standards.

What is an Interface?

An interface is not a class. It is an entity that is defined by the word Interface. An interface has no implementation; it only has the signature or in other words, just the definition of the methods without the body. As one of the similarities to Abstract class, it is a contract that is used to define hierarchies for all subclasses or it defines specific set of methods and their arguments. The main difference between them is that a class can implement more than one interface but can only inherit from one abstract class. Since C# doesn’t support multiple inheritance, interfaces are used to implement multiple inheritance.



Feature
Interface
Abstract class
Multiple inheritance
A class may inherit several interfaces.
A class may inherit only one abstract class.
Default implementation
An interface cannot provide any code, just the signature.
An abstract class can provide complete, default code and/or just the details that have to be overridden.
Access ModfiersAn interface cannot have access modifiers for the subs, functions, properties etc everything is assumed as publicAn abstract class can contain access modifiers for the subs, functions, properties
Core VS Peripheral
Interfaces are used to define the peripheral abilities of a class. In other words both Human and Vehicle can inherit from a IMovable interface.
An abstract class defines the core identity of a class and there it is used for objects of the same type.
Homogeneity
If various implementations only share method signatures then it is better to use Interfaces.
If various implementations are of the same kind and use common behaviour or status then abstract class is better to use.
Speed
Requires more time to find the actual method in the corresponding classes.
Fast
Adding functionality (Versioning)
If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method.
If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly.
Fields and ConstantsNo fields can be defined in interfacesAn abstract class can have fields and constrants defined