Friday, August 31, 2012

Difference between Data table Copy and the Clone method


Data table Copy and the Clone method:
"Both the Copy and the Clone methods create a new Data Table with the same structure as the original Data Table. The new Data Table created by the Copy method has the same set of Data Rows as the original table, but the new Data Table created by the Clone method does not contain any Data Rows."

In summary, Clone method creates a new Data Table with same structure and constraints but without data and Copy method does same but includes data too.

Copy 

datatable newTableCopy;
newTableCopy= existingTable.Copy();

datatable.copy : 
Creates a new datatable along with same structure - (schemas and constraints applied if any) including data in the existing table.

Clone

datatable newTableClone;
newTableClone= existingTable.Clone();.

datatable.Clone():

Creates a new datatable along with same structure with all schemas and constraints excluding data

Differences Between Authentication and Authorization


Authorization is process that comes after authentication and means that application is checking if user have rights to access to some part of web application. Very common example is administration area of site. Depending of user rights, application will allow or deny access to specific pages on site.

An authentication system is how you identify yourself to the computer. The goal behind an authentication system is to verify that the user is actually who they say they are. 
Authorization 
Once the system knows who the user is through authentication, authorization is how the system decides what the user can do. 


There are three major ways to authenticate and authorize users within an ASP.NET Web application:

(1) Windows integrated authentication.
      Identifies and authorizes users based on the server' s users list

(2) Forms authentication.  
     Directs users to a logon Web form that collects user name and password information, and    then authenticates the user against a user list or database that the application maintains.

(3) Passport authentication.
     Directs new users to a site hosted by Microsoft so that they can register a single user name and password that will authorize their access to multiple Web sites.

Wednesday, August 29, 2012

Difference between ASPX and ASCX

S.No
ASPX
ASCX
1
ASP.NET Page uses the extension .aspx
For eg: Default.aspx
User Control uses the extension .ascx
For eg: WebUserControl.ascx.
2
ASP.NET Page begin with a Page Directive.
For eg:
<%@ Page Language="C#"
AutoEventWireup="true"
CodeFile="Default.aspx.cs"
Inherits="_Default" %>

User Control begin with a Control Directive.
For eg:
<%@ Control Language="C#"
AutoEventWireup="true"
CodeFile="WebUserControl.ascx.cs"
Inherits="WebUserControl" %>

3
Usercontrol code can be used in webforms
We can not use webforms in usercontrol.

4
ASP.NET Page can be viewed directly in the Browser.

User Control cannot be viewed directly in the browser. User Controls are added to WebPages and we view them by requesting a web page in our browser
5
ASP.NET page has HTML, Body or Form element.
User Control does not have a HTML, Body or Form element.

Difference between IN and EXISTS


S.NoINEXISTS
1Returns true if specified value matches any value in the sub query or a list.Return true if sub query contain any rows.
2The sub query will run first and then only outer query.The Outer query will ran first and then only sub query.
3IN is slower than EXISTS. The IN is used in the widely For Static variables for eg: select name from table where ID in (Select ID from table2).Exists is faster than IN.The Outer query will run first and then only inner query.So it will reduce the over head. The Exists is useful mostly in IF conditional statements.
4
Example:

SELECT id,
[Name]
FROM dbo.tablea
WHERE id IN (SELECT id
FROM dbo.tableb)
Example:

SELECT id,
[Name]
FROM dbo.tablea AS a
WHERE EXISTS (SELECT id2
FROM dbo.tableb
WHERE id2 = a.id)

Difference between View and Stored Procedure


S.NoViewStored Procedure
1Does not accepts parametersAccept parameters
2Can be used as a building block in large query.Cannot be used as a building block in large query.
3Can contain only one single Select query.Can contain several statement like if, else, loop etc.
4Cannot perform modification to any table.Can perform modification to one or several tables.
5Can be used (sometimes) as the target for Insert, update, delete queries.Cannot be used as the target for Insert, update, delete queries.

Difference between for and foreach loop


S.NoFor loopForeach loop
1In case of for the variable of the loop is always be int only.In case of Foreach the variable of the loop while be same as the type of values under the array. 
2The For loop executes the statement or block of statements repeatedly until specified expression evaluates to false. The Foreach statement repeats a group of embedded statements for each element in an array  or an object collection. 
3There is need to specify the loop bounds(Minimum, Maximum). We do not need to specify the loop bounds minimum or maximum. 
4
example:  
using sytem;
  class class1
  {
      static void Main()
      {
         int j=0;
         for(int i=0; i<=10;i++)
          {
            j=j+1;
          }
           Console.ReadLine();
        }
      }  
example:  
using sytem;
  class class1
  {
     static void Main()
      {
        int j=0;
        int[] arr=new int[] {0,3,5,2,55,34,643,42,23};
        foreach(int i in arr)
        {
           j=j+1;
         }
         Console.ReadLine();
       }
  }  

Difference between ViewState and SessionState


S.NoViewStateSessionState
1
View state is maintained in page level only.
Session state is maintained in session level.
2
View state of one page is not visible in another page.i.e., when user requests another page previous page data will be no longer available.
Session state value is available in all pages within a user session.i.e., The data will be no longer available if user close the browser or session timeout occurs.
3
View state information stored in client only.
Session state information stored in server.
4
View state persist the values of particular page in the client (browser) when post back operation done.
Session state persist the data of particular user in the server. This data available till user close the browser or session time completes.
5
View state used to persist page-instance-specific data.
Session state used to persist the user-specific data on the server side.

Difference between Session and Cookies


S.NoSession StateCookies
1
Session can store any type of data because the value is of datatype of "object"
Cookies can store only "string" datatype
2
These are stored at Server side
They are stored at Client side
3
Session are secured because it is stored in binary format/encrypted form and it gets decrypted at server 
Cookie is non-secure since stored in text format at client side
4
Session is independent for every client i.e individual for every client
Cookies may or may not be individual for every client
5
There is no limitation on size or number of sessions to be used in an application
Due to cookies network traffic will increase.Size of cookie is limited to 40 and number of cookies to be used is restricted to 20.
6
For all conditions/situations we can use sessions
Only in few situations we can use cookies because of no security
7
We cannot disable the sessions.Sessions can be used without cookies also(by disabling cookies)
We can disable cookies
8
The disadvantage of session is that it is a burden/overhead on server
Since the value is string there is no security
9
Sessions are called as Non-Persistent cookies because its life time can be set manually
We have persistent and non-persistent cookies

Difference between Gridview,Datalist and Repeater


  • Gridview - Limited in design, works like an html table. More in built functionality like edit/update, page, sort. Lots of overhead.
  • DataGrid - Old version of the Gridview. A gridview is a super datagrid.
  • Datalist - more customisable version of the Gridview. Also has some overhead. More manual work as you have to design it yourself.
  • ListView - the new Datalist : Almost a hybrid of the datalist and gridview where you can use paging and build in Gridview like functionality, but have the freedom of design. One of the new controls in this family
  • Repeater - Very light weight. No built in functionality like Headers, Footers. Has the least overhead.
    Features of a GridView 
    •Displays data as a table
    •Control over
     –Alternate item
     –Header
     –Footer
     –Colors, font, borders, etc.
     –Paging
    •Updateable
    •Item as row
    Features of Repeater
    •List format
    •No default output
    •More control
    •More complexity
    •Item as row
    •Not updateable
    
    Features of DataList
    •Directional rendering
    •Good for columns
    •Item as cell
    •Alternate item
    •Updateable
    
     Repeater :
        It contains  Header Template, Item template , alternate
    Item template and footer template . it can't support
    Selection, editing, sorting and paging. this is read only
    and fast.
    
    Datalist :
     
       It contains Header Template, Item template , alternate
    Item template , Edit itm template and footer template . it
    can't support  sorting and paging but  support selection and
    editing
    
    DataGrid(or GridView) :
    
    It contains Header Template, Item template , alternate Item
    template , Edit itm template and footer template . it can
    support selection, editing , sorting and paging . Mostly
    every developer caught used this control  .

Monday, August 27, 2012

Difference between DataTable.Copy and DataTable.Clone


Both the methods DataTable.Clone and DataTable.Copyare are used to make copies of existing datatables, the difference is

DataTable.Clone() - Copies only the structure of the source table with the constraints, the data is not copied from the source table.

DataTable.Copy() - Copies the structure and data from the source table.


Example: 
DataTable.Clone()
DataTable dt;
dt= sourceTable.Clone();

Here, the targetTable is created with only the structure of the sourceTable
targetTable.Rows.Count() returns 0.

Example: DataTable.Copy()
DataTable dt;
dt= sourceTable.Copy();

Tuesday, August 21, 2012

Difference Between TRUNCATE & DELETE

TRUNCATE
DELETE
faster and uses fewer system and transaction log resources than DELETE.
 Slower than truncate because, it maintain logs for every record.
removes the data by deallocating the data pages used to store the tables data, and only the page deallocations are recorded in the transaction log.
removes  rows one at a time and records an entry in the transaction log for each deleted row.
removes all rows from a table, but the table structure and its columns, constraints, indexes and so on remain. The counter used by an identity for new rows is reset to the seed for the column.
If you want to retain the identity counter, use DELETE instead. If you want to remove table definition and its data, use the DROP TABLE statement.
You cannot use TRUNCATE TABLE on a table referenced by a FOREIGN KEY constraint;
use DELETE statement without a WHERE clause
Because TRUNCATE TABLE is not logged, it cannot activate a trigger.
Activates Trigger
No Roll back
Can Rollback
DDL Command
DML Command

Difference between EXE and DLL

- EXE stands for Extensible Execute File and DLL stands for Dynamic Link Library. It is also called assembly in Dot Net.

- EXE gives direct output, it needs a resource and DLL does not give direct output, it always execute with any software and provide resource to that software.

- EXE is use by End User like-Client but DLL can not use by End User.

- An ActiveX Dll runs is an in process server running in the same memory space as the client process and an ActiveX Exe is an out of process server which runs in it's own separate memory space.

- EXE runs independently, whereas DLL runs within an EXE. DLL is an in-process file and EXE is an out-process file.

- A DLL would share the same process and memory space of the calling application while an EXE creates its separate process and memory space.

- And another difference is that EXEs are executable programs while DLLs are libraries loaded into a process and contain some sort of useful functionality like security, database access or something.

- EXE is mainly executable files which execute when user run the programs or click on them whereas DLL contains the function and procedure which link dynamically when needs them.

Difference between WCF and Web service


Web service is a part of WCF. WCF offers much more flexibility and portability to develop a service when comparing to web service. Still we are having more advantages over Web service, following table provides detailed difference between them.

FeaturesWeb ServiceWCF
HostingIt can be hosted in IISIt can be hosted in IIS, windows activation service, Self-hosting, Windows service
Programming[WebService] attribute has to be added to the class[ServiceContraact] attribute has to be added to the class
Model[WebMethod] attribute represents the method exposed to client[OperationContract] attribute represents the method exposed to client
OperationOne-way, Request- Response are the different operations supported in web serviceOne-Way, Request-Response, Duplex are different type of operations supported in WCF
XMLSystem.Xml.serialization name space is used for serializationSystem.Runtime.Serialization namespace is used for serialization
EncodingXML 1.0, MTOM(Message Transmission Optimization Mechanism), DIME, CustomXML 1.0, MTOM, Binary, Custom
TransportsCan be accessed through HTTP, TCP, CustomCan be accessed through HTTP, TCP, Named pipes, MSMQ,P2P, Custom
ProtocolsSecuritySecurity, Reliable messaging, Transactions

Features of WCF

  • Service Orientation
  • Interoperability
  • Multiple Message Patterns
  • Service Metadata
  • Data Contracts
  • Security
  • Multiple Transports and Encodings
  • Reliable and Queued Messages
  • Durable Messages
  • Transactions
  • AJAX and REST Support
  • Extensibility
WCF is a replacement for all earlier web service technologies from Microsoft. It also does a lot more than what is traditionally considered as "web services".

Thursday, August 16, 2012

SQL SERVER – Introduction to JOINs – Basic of JOINs


The nature of relational database design shows that we will have related data that is stored in different tables. To retrieve data from two or more tables we use JOINS.

The JOIN clause tells the database how the data in the two tables is related so that it can return a correct representation of the related data.

There are different types of join. 

1. Self-Join 
2. Inner-Join 
3. Outer-Join 
   3.1 RightOuterJoin 
   3.2 LeftOuterJoin 
   3.3 FullOuterJoin 
4. Cross join 

Self Join : Select e1.emp_name 'manager',e2.emp_name 'employee' 
from employees e1 join employees e2 on e1.emp_id=e2.emp_manager_id 











Sunday, August 5, 2012

Difference Between ToString() vs Convert.ToString()


ToString() raise exception when the object is null
So in the case of object.ToString(), if object is null, it raise NullReferenceException.
Convert.ToString() return string.Empty in case of null object
(string) cast assign the object in case of null
So in case of
MyObject o = (string)NullObject;
But when you use o to access any property, it will raise NullReferenceException.
Example : int i =0;    MessageBox.Show(i.ToString());        MessageBox.Show(Convert.ToString(i));
We can convert the integer “i” using “i.ToString()” or “Convert.ToString” so what’s the difference.
The basic difference between them is “Convert” function handles NULLS while “i.ToString()”
does not it will throw a NULL reference exception error. So as good coding practice using
“convert” is always safe.


Code Sample :

C#
    public String FullName = null;
    protected void Page_Load(object sender, EventArgs e)
    {

        try
        {
            Response.Write("<b>.ToString</b><br>");
            Response.Write("FullName :" + FullName.ToString());
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }

        Response.Write("<br><br>");

        try
        {
            Response.Write("<b>Convert.ToString</b><br>");
            Response.Write("FullName :" + Convert.ToString(FullName));
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }

    }

                         OutPut: