Sunday 27 May 2012

Abstract Class in C#



The class which can't be instantiated (we can't create Object for this class) is known as an Abstract Class. This particular article contains the details of an Abstract Class.
Introduction:
The class which cannot be instantiated is known as an Abstract Class. That is, an object of  it can’t be created. But it should be inherited.
Features of an Abstract Class
*we can't create Object for this class
*An Abstract Class Should is inherited.
*It may have use Methods.
*It may have Abstract Methods.
*An Abstract Method of an Abstract Class should be overridden.
*An Abstract Class can only contain Abstract Method.

We can't create Object for this class:

Error Message:


An Abstract Class Should is inherited :

Result:
It may have use Methods:


 Result:

It may have Abstract Methods:

Error Message:



An Abstract Class can only be in Abstract Method





Thursday 24 May 2012

SQL FULL JOIN



The FULL JOIN keyword return rows when there is a match in one of the tables.
Syntax:
SELECT column_name(s) FROM tablename1  FULL JOIN tablename2 ON tablename1.column_name=tablename2.column_name

For Example,
The "Customer" table:
PId
LastName
FirstName
Address
City
1
Vaishnavi
Ola
Anna Nagar
Sandnes
2
Shajil
Tove
T Nagar
Sandnes
3
Vinoth
Kari
Shivaji St, T Nagar
Stavanger

The "Orders" table:
O_Id
OrderNo
PId
1
77895
3
2
44678
3
3
22456
1
4
24562
1
5
34764
15
Now we want to list all the Customer and their orders, and all the orders with their Customer.
Query like,
SELECT Customer.Name, Customer.City, Orders.OrderNo FROM Customer FULL JOIN Orders ON Customer.PId=Orders.PId ORDER BY Customer.Name
The result-set:
LastName
City
OrderNo
Vaishnavi
Bangalore
22456
Vaishnavi
Bangalore
24562
Vinoth
Chennai
77895
Vinoth
Chennai
44678
Shajil
Chennai
34764



The FULL JOIN keyword returns all the rows from the left table (Customer), and all the rows from the right table (Orders). If there are rows in "Customer" that do not have matches in "Orders", or if there are rows in "Orders" that do not have matches in "Customer", those rows will be listed as well.

SQL RIGHT JOIN


The RIGHT JOIN keyword returns all the rows from the right table (tablename2), even if there are no matches in the left table (tablename1).
Syntax:
SELECT column_name(s) FROM tablename1 RIGHT JOIN tablename2
ON tablename1.column_name=tablename2.column_name
Note: In some databases RIGHT JOIN is called RIGHT OUTER JOIN.
For Example,
The "Customer" table:
PId
Name
Address
City
1
Vaishnavi
Anna Nagar
Bangalore
2
Shajil
T Nagar
Chennai
3
Vinoth
Shivaji St, T Nagar
Chennai
The "Orders" table:
O_Id
OrderNo
PId
1
77895
3
2
44678
3
3
22456
1
4
24562
1
5
34764
15

 Query like,
SELECT  Customer.Name, Customer.City, Orders.OrderNo  FROM Customer
RIGHT JOIN  Orders  ON  Customer.PId=Orders.PId  ORDER BY Customer.Name
The result-set:
LastName
City
OrderNo
Vaishnavi
Bangalore
22456
Vaishnavi
Bangalore
24562
Vinoth
Chennai
77895
Vinoth
Chennai
44678


34764
The RIGHT JOIN keyword returns all the rows from the right table (Orders), even if there are no matches in the left table (Customer).

Tuesday 22 May 2012

ASP.Net ValidationGroup


ASP.NET ValidationGroup Property:
Definition and Usage of ValidationGroup in asp.net

The ValidationGroup property specifies which group of controls is validated on validation.

This property is mostly used when there are several buttons in a form.
 Syntax
 <asp:Button ValidationGroup="group" runat="server" />

Attribute        Description
   group          The validation group to validate.

The Following example give clear view of validation group in asp.net:


<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Welcome to ASP.NET Validation Group Example!!!
    </h2>
    <asp:Button ID="Button2" runat="server" Text="Button1" ValidationGroup="ValGroup1" />
    <asp:Button ID="Button1" runat="server" Text="Button2"  ValidationGroup="ValGroup2" />
     <asp:Button ID="Button3" runat="server" Text="Button3" ValidationGroup="ValGroup3" />
    <asp:Button ID="Button4" runat="server" Text="Button4"  ValidationGroup="ValGroup4" />
 
    <p>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator runat="server" ID="ref1" ErrorMessage="FillTextBox1" ControlToValidate="TextBox1"
        ValidationGroup="ValGroup1" ForeColor="Red"></asp:RequiredFieldValidator>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
             <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1"   ControlToValidate="TextBox2"
               ValidationGroup="ValGroup2" ErrorMessage="FillTextBox2"  ForeColor="Blue"> </asp:RequiredFieldValidator>
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
             <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator2"  ControlToValidate="TextBox3"
             ValidationGroup="ValGroup3"  ErrorMessage="FillTextBox3"  ForeColor="Green"> </asp:RequiredFieldValidator>
        <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
             <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator3"  ControlToValidate="TextBox4"
             ValidationGroup="ValGroup4" ErrorMessage="FillTextBox4"  ForeColor="Brown"></asp:RequiredFieldValidator>
      </p>
    <p>
       
    </p>
</asp:Content>




Monday 21 May 2012

Differences between Classes and Structs:


Classes and Structs:
     Classes and structs both are essentially templates from which you can create objects,
Each Objectr has data and methods to manipulate and access that data.The class defines what
data and functionality each particular object(called instance) of that class can contain.
For Example:
             If you have a class that repesents a customer ,it might define fields such as
CustomerId,FirstName,LastName,Age,salary,etc..which you will use to hold information about a
particular customer.it might also define functionality that acts upon the data stored in these
fields.you can instantiate an object of this class to represent one specific customer,set the
field values for that instance, and use its funtionality.


Class Customer
{
   Public int CustomerID;
   public string FirstName;
   public String LastName;

}

Structs differ from classes in the way that they are stored inn memory and accessed(Classes
are reference types stored in heap,structs are vlaue type stored on the stock),and in some
of the features(for example structs don't support inheritance).you will tend to use structs
for smaller data types for  performance reasons. In term of syntax,structs look very similar
to classes;the main difference is that you use the keyword  struct instead of class to declare
them.

Struct Customerstruct
{
   Public int CustomerID;
   public string FirstName;
   public String LastName;

}

For Both Classes and structs, you use the keyword new to declare an instance:This keyword creates
the object and initializes it, in the following example,the default behavior Zero out its fields


     Customer cust = new Customer();//works for a class
     Customerstruct custstu = new Customerstruct();//works for a structs

we will see what is classmember in next topic.    

SQL IN Operator


The IN operator helps to reduce the need of  multiple OR conditions.


The syntax for the IN operators is:


SELECT columns
FROM tables
WHERE column1 in (value1, value2, .... value_n);


This SQL statement will return the records where column1 is value1, value2..., or value_n. 
The IN operators can be used in any valid SQL statement - select, insert, update, or delete.


The number of values in the parenthesis can be one or more, with each values separated by comma. 
Values can be numerical or characters. If there is only one value inside the parenthesis, this commend is equivalent to,


IN Operator Example


The "Customer" table:


CUS_Id LastName        FirstName     Address        City
1         Kumar             vinoth        Trivensn10 surandai
2         lakshmi           Vijaya        daospd23         surandai
3         latha               Hema                Reodj20        kadayam


Now we want to select the persons with a last name equal to "Kumar" or "latha" from the table above.


We use the following SELECT statement:


SELECT * FROM Customer
WHERE LastName IN ('Kumar','latha')


The result-set will look like this:


CUS_Id LastName        FirstName     Address        City
1       Kumar               vinoth        Trivensn10  surandai
3         latha                 hema              Reodj20          kadayam

Sunday 20 May 2012

COALESCE Function in SQL TO Avoid Null in its arguments.


The COALESCE function in SQL returns the first non-NULL expression among its given columns

 Examples, say we have the following table,
Table Personel_Contact
Name Business_Num Cell_Num         Home_Num
Vinoth        9684637284 9674736743 9685847364
Ravi           NULL                  9583525487     7859493859
Suresh       NULL                  NULL              7675847393
and we want to find out the best way to contact each person according to the following rules:

1. If a person has a business phone, it will return the Business phone number.

2. If a person does not have a business phone and has a cell phone, it will return the cell phone number.

3. If a person does not have a business phone, does not have a cell phone, and has a home phone, it will return the home phone number.

We can use the COALESCE function to achieve our goal:

SELECT Name, COALESCE(Business_Num,Cell_Num,Home_Num) Cont_Num
FROM Personel_Contact;

Result:

Name Cont_Num
vinoth 9684637284
Ravi         9583525487
suresh      7675847393

Friday 18 May 2012

SQL LEFT JOIN:



The LEFT JOIN keyword returns all rows from the left table (table1), even if there are no matches in the right table (table2).
Note that : the  left and  Right  joins  are  refered  as  OUTER  JOIN.
Syntax
SELECT column_name(s) FROM tablename1 as t1 LEFT JOIN tablename2 as t2 ON t1.column_name=t2.column_name

SQL LEFT JOIN Example:
The table “Customer” is,
Id
Name
Address
City
1
Vaishnavi
 10,Anna Nagar
Bangalore
2
Shajil
 23,T.Nagar
Chennai
3
Vinoth
 20,Sivaji Street
Chennai
The  table “Order” is,
O_Id
OrderNo
Id
1
77895
3
2
44678
3
3
22456
1
4
24562
1
5
34764
15
Query:
SELECT C.Name, C.City, O.OrderNo FROM Customer as C LEFT JOIN Orders as O ON C.Id=O.Id
The result-set will be:
Name
City
OrderNo
Vaishnavi
Bangalore
22456
Vaishnavi
Bangalore
24562
Vinoth
Chennai
77895
Vinoth
Chennai
44678
Shajil
Chennai
The LEFT JOIN keyword returns all the rows from the left table (Customers), even if there are no matches in the right table (Orders).