Join Us On Facebook

Please Wait 10 Seconds...!!!Skip

Tuesday, 23 April 2013

Using of COALESCE() and ISNULL() in Sql Server


COALESCE() function -The COALESCE function returns the first non-NULL value from a provided list of expressions. The COALESCE function is passed an undefined number of arguments and it tests for the first nonnull expression among them.If all arguments are NULL then COALESCE returns NULL.

The syntax is as follows:

COALESCE(expression [,...n])

Suppose we have 'employee' table with some data-

we can see that there are some null in mobile column and some null in phone column, so if we need contact details of employee,it may be mobile or phone(if mobile is null then phone and if both are null then it will return null)
so In this case we have to use COALESCE function.

After executing this query, we have found this result-


this is all about COALESCE() function , now Let's discuss about ISNULL() function-

ISNULL() function-
ISNULL validates if an expression is NULL, and if so, replaces the NULL value with an alternate value. In this example, any NULL value will be replaced with a different value.
Suppose we want to mobile number of employee table, and if any value is null in mobile column then we have to return 'unknown' word in place of null as a alternative value,then we write following query -

The result set is come in this way-


Difference between ISNULL and COALESCE-
  • ISNULL is limited to two arguments but in COALESCE we can use more number of arguments
  • Performancewise COALESCE is faster than ISNULL
  • COALESCE is ANSI SQL standard whereas ISNULL is a proprietary TSQL function
  • Using select ISNULL(NULL, NULL) doesn’t throw error but select COALESCE(NULL, NULL) throw an  error




Saturday, 6 April 2013

Validation controls are provided by ASP.NET


There are six main types of validation controls:-
1.RequiredFieldValidator-
It checks whether the control have any value. It is used when you want the control should not be
empty.After apply it on control , users should compulsory to fill value in that control. For Example-In login page-


2.RangeValidator-
It checks if the value in validated control is in that specific range. Example TxtCustomerCode
should not be more than eight lengths. For Example-



3.CompareValidator-
It checks that the value in controls should match some specific value. Example Textbox TxtPie
should be equal to 3.14. For Example- For conforming password in user account page-


4.RegularExpressionValidator-
When we want the control, value should match with a specific regular expression.For Example-
Suppose you want to validate email in textbox,then you use RegularExpressionValidator with specific RegularExpression.

5.CustomValidator-
It is used to define User Defined validation.For Example-
Suppose you want to enter character between 6 to 15 in any textbox(username)-

Similarities and difference between Class and structure in C#


Following are the similarities between classes and structures:-
• Both can have constructors, methods, properties, fields, constants, enumerations,
events, and event handlers.
• Structures and classes can implement interface.
• Both of them can have constructors with and without parameter.
• Both can have delegates and events.


Following are the key differences between them:-
• Structures are value types and classes are reference types. So structures use stack
and classes use heap.
• Structures members cannot be declared as protected, but class members can be. You
cannot do inheritance in structures.
• Structures do not require constructors while classes require.
• Objects created from classes are terminated using Garbage collector. Structures are
not destroyed using GC.

Something about WCF


Definition of WCF 
Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF we can build secure, reliable, transacted solutions that integrate across platforms.
WCF is a unified framework which provides :
1. NET Remoting
 2.Distributed Transactions
 3.Message Queues and 
4.Web Services into a single service-oriented programming model for distributed computing.
WCF interoperate between WCF-based applications and any other processes that communicate via SOAP (Simple Object Access Protocol) messages.

Features of WCF

  1. Service Orientation
  2. Interoperability
  3. Multiple Message Patterns
  4. Service Metadata
  5. Data Contracts
  6. Security
  7. Multiple Transports and Encodings
  8. Reliable and Queued Messages
  9. Durable Messages
  10. Transactions
  11. AJAX and REST Support
  12. Extensibility
To know more about features of WCF see: http://msdn.microsoft.com/en-us/library/ms733103.aspx

Useful terms of WCF
A WCF service is exposed to the outside world as a collection of endpoints.
1. Endpoint: Endpoint is a construct at which messages are sent or received (or both). Endpoint comprises of ABC’s       
What are ABC’s of WCF ? 
A. Address - Address is a location that defines where messages can be sent
B. Binding - Binding is a specification of the communication mechanism (a binding) that described how messages should be sent
C. Contract - Contract is a definition for a set of messages that can be sent or received (or both) at that location (a service contract) that describes what message can be sent.
2. Service: A construct that exposes one or more endpoints, with each endpoint exposing one or more service operations.
3. Contracts: A contract is a agreement between two or more parties for common understanding and it is a is a platform-neutral and standard way of describing what the service does. In WCF, all services expose contracts.
Types of Contracts:
1) Operation Contract: An operation contract defines the parameters and return type of an operation.
1
2
[OperationContract]
double MUL(int i, intj);
2) Service Contract: Ties together multiple related operations contracts into a single functional unit.
1
2
3
4
5
6
7
8
9
10
11
12
[ServiceContract] //System.ServiceModel
public interface IMath
{
    [OperationContract]
    double MUL(int i, int j);
    [OperationContract]
    double DIV(int i, int j);    
}
3) Data Contract: The descriptions in metadata of the data types that a service uses.
1
2
3
4
5
6
7
8
9
10
11
12
13
// Use a data contract
[DataContract] //using System.Runtime.Serialization
public class Complex
{
    private int real;
    private int imaginary;
 
    [DataMember]
    public int Real { get; set; }
 
    [DataMember]
    public int Imaginary { get; set; }
}