Tuesday, April 16, 2013

Difference between a Label and Literal control in asp.net

Lable
System.Object
  System.Web.UI.Control
    System.Web.UI.WebControls.WebControl
      System.Web.UI.WebControls.Label
<asp:Label ID="lblFirstName" runat="server" CssClass="myCssClass"Text="First Name" />
Literal
System.Object
  System.Web.UI.Control
    System.Web.UI.WebControls.Literal 
<asp:Literal id="litFirstName" runat="server" Text="First Name" />
Now, bind your controls with some text :-
lblFirstName.Text = "text";
litFirstName.Text = "text";

Output will be show html of page run-time

<span id="lblFirstName">text</span>
<br />
text
------------------------------------------------------------------------------
we see that the label text is wrapped around a span tag and the literal text is simply putting a text in it. 
label control has much more properties than the literal control, so choose wisely. 

Sunday, September 9, 2012

Difference between Web Site and Web application in ASP.NET

• Development Wise Difference

Web Site
1. We can code one page in C# and one page in vb.net .
2. We cannot call (access) public functions from one page to other page.
3. Utility classes / functions must be placed in a special ASP.NET solder(the App_Code folder) 
4. Web Sites do not have a .csproj/.vbproj file that manages the project (the folder that contains the site becomes the project root). 
5. In the Web Site project, each file that you exclude is renamed with an exclude
keyword in the filename.
6. Explicit namespaces are not added to pages, controls, and classes by default, but you can add them manually.

Web Applications
1. Only one programming language allowed per project (Need to decide on programming language when starting project). 
2. We can access public functions from one page to other page.
3. Utility classes / function can be placed anywhere in the  Applications  folder structure. 
4. Web Applications are treated like other .NET Projects and are managed by a project file (.csproj or .vbproj) . 
5. One nice feature of the Web Application Project is it's much easier to exclude files from the project view.
6. Explicit namespaces are added to pages, controls, and classes by default.

• Deployment wise difference

Web Site
1. It has its code in a special App_Code directory and it's compiled into several DLLs (assemblies) at runtime.
2. No need to recompile the site before deployment. 
3. We need to deploy both .aspx file and code behind file. 
4. Small changes to the site do not require a full re-deployment. (We can upload the code file that was changed) 

Web Application
1. web application is precompiled into one single DLL.
2. Site has to be pre-compiled before deployment .
3. Deploy only .aspx page, but not associated code file (the pre-compiled dll will be uploaded) .
4. Even small changes require a full re-compile of the entire site(i.e. if the code for a single page changes the whole site must be compiled) (It requires careful planning to ensure new bugs aren't introduced to the production site when uploading bug fixes or other changes.) 

Thursday, September 6, 2012

Difference between Primary Key and Foreign Key

primary key is a column which uniquely identifies the records in a table. In a broad sense, a primary key is the mixture of a unique key and an index: A collumn with a primary key is indexed to deliver a faster query, and doesn't allow duplicate values to ensure specific data.
Most programmers recommend all tables having a primary key (and only one) to enhance the speed of queries and overall database performance.
An example of a primary key may be found in a table named "departments," which might have a collumn named "department_number" that uniquely identifies each department in the table with a number.
foreign key is a column (the child column) in a table which has a corresponding relationship and a dependency on another column (the parent collumn) that is usually in a different table. Parent columns can have multiple child collumns, but a child collumn can only have one parent column.
The child collumn is the collumn with the foreign key; the parent collumn does not have the foreign key "set" on it, but most databases require the parent collumn to be indexed.
Foreign keys are made to link data across multiple tables. A child collumn cannot have a record that its parent collumn does not have.
Say a table named "employees" has 20 employees (rows) in it. There are 4 departments in the "departments" table. All 20 employees must belong to a department, so a collumn in the "employees" table named "department" would point to the primary key in the "departments" table using a foreign key. Now all employees must belong to a department as specified by the "departments" table. If a department isn't specified in the "departments" table, the employee cannot be assigned to it.

Difference between DDL, DML and DCL commands


DDL – Data Definition Language: statements used to define the database structure or schema. Some examples:
  • CREATE – to create objects in the database
  • ALTER – alters the structure of the database
  • DROP – delete objects from the database
  • TRUNCATE – remove all records from a table, including all spaces allocated for the records are removed
  • COMMENT – add comments to the data dictionary
  • RENAME – rename an object
They are called Data Definition since they are used for defining the data. That is the structure of the data is known through these DDL commands.
DML – Data Manipulation Language: statements used for managing data within schema objects. Some examples:
  • SELECT – retrieve data from the a database
  • INSERT – insert data into a table
  • UPDATE – updates existing data within a table
  • DELETE – deletes all records from a table, the space for the records remain
  • MERGE – UPSERT operation (insert or update)
  • CALL – call a PL/SQL or Java subprogram
  • EXPLAIN PLAN – explain access path to data
  • LOCK TABLE – control concurrency
DML commands are used for data manipulation. Some of the DML commands
insert,select,update,delete etc. Even though select is not exactly a DML language command oracle still recommends you to consider SELECT as an DML command.
DML are not auto-commit. i.e. you can roll-back the operations, but DDL are auto-commit
DCL – Data Control Language. Some examples:
  • GRANT – gives user’s access privileges to database
  • REVOKE – withdraw access privileges given with the GRANT command
Data Control Language is used for the control of data. That is a user can access any data based on the priveleges given to him. This is done through DATA CONTROL
It is used to create roles, permissions, and referential integrity as well it is used to control access to database by securing it.
TCL – Transaction Control: statements used to manage the changes made by DML statements. It allows statements to be grouped together into logical transactions.
  • COMMIT – save work done
  • SAVEPOINT – identify a point in a transaction to which you can later roll back
  • ROLLBACK – restore database to original since the last COMMIT
  • SET TRANSACTION – Change transaction options like isolation level and what rollback segment to use
For revoking the transactions and to make the data commit to the database we use TCL. 

Once we commit we cannot rollback. Once we rollback we cannot commit.
Commit and Rollback are generally used to commit or revoke the transactions that are with regard to DML commands.

Difference between Boxing And Unboxing


Tuesday, September 4, 2012

Difference between Public, Private, Protected .....


Public : Allows access to the class member from any other class.
Private : Allows access to the class member only in the same class.
Protected : Allows access to the class member only within the same class and from inherited classes.
Internal : Allows access to the class member only in the same assembly.
Protected internal : Allows access to the class member only within the same class, from inherited classes, and other classes in the same assembly.
Static : Indicates that the member can be called without first instantiating the class.

Difference between an Interface and an Abstract class


There are quite a big difference between an interface and an abstract class, even though both look similar.
    • Interface definition begins with a keyword interface so it is of type interface
    • Abstract classes are declared with the abstract keyword so it is of type class
    • Interface has no implementation, but they have to be implemented.
    • Abstract class’s methods can have implementations and they have to be extended.
    • Interfaces can only have method declaration (implicitly public and abstract) and fields (implicitly public static)
    • Abstract class’s methods can’t have implementation only when declared abstract.
    • Interface can inherit more than one interfaces
    • Abstract class can implement more than one interfaces, but can inherit only one class
    • Abstract class must override all abstract method and may override virtual methods
    • Interface can be used when the implementation is changing
    • Abstract class can be used to provide some default behavior for a base class.
    • Interface makes implementation interchangeable
    • Interface increase security by hiding the implementation
    • Abstract class can be used when implementing framework
    • Abstract classes are an excellent way to create planned inheritance hierarchies and also to use as non-leaf classes in class hierarchies.