Introduction for WPF






Windows Presentation Foundation :


As the name says all, WPF is actually a new framework introduced with .NET framework 3.0 which actually puts forward a new set of classes and assemblies which allow us to write programs more efficiently and flexibly. It uses Direct3D rendering which employs graphics cards to render the output on the screen. Thus the drawing in the form will be smooth and also there is a chance to utilize the hardware capabilities installed in your machine. In case of traditional GDI forms application, it is not possible to use advanced graphics capabilities and hence Windows Forms application will always be inefficient in comparison to WPF. Another important thing that I must address in this regard, GDI Windows forms application uses Operating system controls to build its application. Thus it is basically very hard to customize them in your own application. WPF controls are actually drawn over the screen, and hence you can customize controls totally and modify their behavior when required.


Difference b/w Windows Forms and WPF Application :


Features of WPF :



WPF comes with lots of advantages. Let me introduce a few of its features:



  • Device Independent Pixel (DPI)

    WPF introduces Device Independent DPI Settings for the applications built with it. For a window, it is very
    important to calculate how many Dots Per inch(DPI) the screen could draw. This is generally dependent on the
    hardware device and operating system in which the application runs and also how the DPI settings is applied on
    the Device. Any user can easily customize these settings and hence make the application look horrible. Windows
    forms application uses pixel based approach so with changing DPI settings, each control will change its size and
    look.

    WPF addresses this issue and makes it independent of DPI settings of the computer. Let's look at
    how it is possible:


    Let's say you have drawn a box, just like the one in the figure, which is 1 inch long in 96 dpi
    screen. Now if you see the same application in 120 dpi settings, the box will appear smaller. This is because
    the things that we see on the screen are totally dependent on dpi settings.

    In case of WPF, this is
    modified to density based approach. That means when the density of pixel is modified, the elements will adjust
    them accordingly and hence the pixel of WPF application is Device Independent Pixel. As you can see in the
    figure, the size of the control remains the same in case of WPF application and it takes more pixels in
    case of 120 DPI application to adjust the size properly.


  • Redefine Styles and Control Templates

    In addition to graphics and animation
    capabilities, WPF also comes with a huge flexibility to define the styles and ControlTemplates.
    Style based technique as you might come across with CSS is a set of definitions which defines how the controls
    will look like when it is rendered on the screen. In case of traditional windows applications, styles are tightly
    coupled with each control, so that you need to define color, style, etc. for each individual control to make it
    look different. In case of WPF, Styles are completely separated from the UIElement. Once you define
    a style, you can change the look and feel of any control by just putting the style on the element.

    Most of
    the UIElements that we generally deal with are actually made using more than one individual elements.
    WPF introduces a new concept of Templates, which you might use to redefine the whole control itself.
    Say for instance, you have a CheckBox, which has a Rectangle in it and a
    ContentPresenter (one where the caption of the TextBox appears). Thus you can redefine
    your checkbox and put a ToggleButton inside it, so that the check will appear on the
    ToggleButton rather than on the Rectangle. This is very interesting. We will look into
    more detail on Styles and ControlTemplates in later section of the article.



  • What is XAML?


    According to the definition, XAML is an XML based declarative markup language for specifying and setting the
    characteristics of classes. In other words, XAML is a language used by WPF, Silverlight or any other application
    which can declare classes by itself. So, you can declare a variable, define the properties of any class and
    directly use it in your application. The XAML parser will automatically parse and create the actual object
    while it renders the application.

    XAML is generally used to define layout of UI, its elements and
    objects for static and visual aspect. We cannot define flow of a program using XAML. So even though there are
    large capabilities of XAML, it is actually not a programming language, rather it is used to design UI of the
    application. Thus XAML employs other programming languages like C#, VB.NET, etc. to define the logic in code
    behind.

    ExpressionBuilder is the best tool to generate XAML.


    WPF Architecture







    For every new technology, it is very essential to have a clear idea about its architecture. So before beginning
    your application, you must grab a few concepts. If you would not like to know WPF in detail, please skip this
    section. As mentioned earlier, WPF is actually a set of assemblies that build up the entire framework. These
    assemblies can be categorized as:

    • Managed Layer
    • UnManaged Layer

    • Core API

    Managed Layer: Managed layer of WPF is built using a number of
    assemblies. These assemblies build up the WPF framework, communicate with lower level unmanaged API to render its
    content. The few assemblies that comprise the WPF framework are:

    1. PresentationFramework.
      dll
      : Creates the top level elements like layout panels, controls, windows, styles, etc.

    2. PresentationCore.dll: It holds base types such as UIElement,
      Visual from which all shapes and controls are Derived in PresentationFramework.dll.

    3. WindowsBase.dll: They hold even more basic elements which are capable of being used
      outside the WPF environment like Dispatcher object, Dependency Objects. I will discuss
      each of them later.

    Unmanaged Layer (milcore.dll): The unmanaged layer
    of WPF is called milcore or Media Integration Library Core. It basically translates the WPF higher level objects
    like layout panels, buttons, animation, etc. into textures that Direct3D expects. It is the main
    rendering engine of WPF.

    WindowsCodecs.dll: This is another low level API which
    is used for imaging support in WPF applications. WindowsCodecs.dll comprises a number of codecs which
    encode / decode images into vector graphics that would be rendered into WPF screen.

    Direct3D: It is the low level API in which the graphics of WPF is rendered.

    User32: It is the primary core API which every program uses. It actually manages memory and process separation.

    GDI & Device Drivers: GDI and Device Drivers are specific to the operating system which is also used from the application to access low level APIs.


    Building Your First WPF Application :


    Now the time has come to build your first WPF Application.
    To do this, let's open Visual Studio 2008 / 2010. For this example, I used Visual Studio 2008. Create a new
    Project. You will see a new window. The XAML will look like:

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

    <
    Window x:Class
    ="FirstWindowsApplication.Window1"
     xmlns
    ="
    http://schemas.microsoft.com/winfx/2006/xaml/presentation"

       xmlns:x
    ="http://schemas.microsoft.com/winfx/2006/xaml"
     x:Name="Window1"  
     Title="Window1" Height="300" Width="300">  
      <Grid>   
     </Grid> 
    </Window>
    *******************************************************

    Here the blank window is produced. Height / Width represents the Size of the

    Window. Title determines the text which is displayed in the TitleBar of the

    window. Every control in XAML could be named with x:Name attribute. This will

    be used to reference the Window object in your XAML. x:Class attribute

    represents the class which should be associated with current Window.

    As I already told you, that XAML is not self sufficient, so to define

    logic you need a class in C# or VB.NET.

    Grid is the primary layout for WPF application. Grid can take multiple

    Child elements. So let us put some controls into the grid.

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

    <Grid>   
     <Grid.RowDefinitions>  
    <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
    <ColumnDefinition MinWidth="50" />
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <TextBlock Text="Enter Name :" Grid.Row="0" Grid.Column="0" />
    <TextBox x:Name="txtName" Grid.Row="0" Grid.Column="1" MinWidth="50"/>
    <Button Content="Click Me" Grid.Row="0" Grid.Column="2" Click="Button_Click"/>
    </Grid>
    *******************************************************

    You can see that I have defined RowDefination and ColumnDefination.

    This allows you to divide the grid into cells so that you can place your

    control exactly where you want to. For each RowDefination and ColumnDefination,

    you can use Height and Width of it. You can see I have used 50, Auto,

    and * as width. Auto represents the size which we would define for the control

    during control definition. * indicates the rest of the space which it can

    take. Thus, you can see the button is spread the rest of the area of the

    column it finds.

    Now in the Behind, I put a Messagebox to show the content of TextBox.

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

    private void Button_Click(object sender, RoutedEventArgs e) 
     {  
        MessageBox.Show(string.Format("Hi {0}", this.txtName.Text)); 
     }
    ********************************************************************






Windows Presentation Foundation :


As the name says all, WPF is actually a new framework introduced with .NET framework 3.0 which actually puts forward a new set of classes and assemblies which allow us to write programs more efficiently and flexibly. It uses Direct3D rendering which employs graphics cards to render the output on the screen. Thus the drawing in the form will be smooth and also there is a chance to utilize the hardware capabilities installed in your machine. In case of traditional GDI forms application, it is not possible to use advanced graphics capabilities and hence Windows Forms application will always be inefficient in comparison to WPF. Another important thing that I must address in this regard, GDI Windows forms application uses Operating system controls to build its application. Thus it is basically very hard to customize them in your own application. WPF controls are actually drawn over the screen, and hence you can customize controls totally and modify their behavior when required.


Difference b/w Windows Forms and WPF Application :


Features of WPF :



WPF comes with lots of advantages. Let me introduce a few of its features:



  • Device Independent Pixel (DPI)

    WPF introduces Device Independent DPI Settings for the applications built with it. For a window, it is very
    important to calculate how many Dots Per inch(DPI) the screen could draw. This is generally dependent on the
    hardware device and operating system in which the application runs and also how the DPI settings is applied on
    the Device. Any user can easily customize these settings and hence make the application look horrible. Windows
    forms application uses pixel based approach so with changing DPI settings, each control will change its size and
    look.

    WPF addresses this issue and makes it independent of DPI settings of the computer. Let's look at
    how it is possible:


    Let's say you have drawn a box, just like the one in the figure, which is 1 inch long in 96 dpi
    screen. Now if you see the same application in 120 dpi settings, the box will appear smaller. This is because
    the things that we see on the screen are totally dependent on dpi settings.

    In case of WPF, this is
    modified to density based approach. That means when the density of pixel is modified, the elements will adjust
    them accordingly and hence the pixel of WPF application is Device Independent Pixel. As you can see in the
    figure, the size of the control remains the same in case of WPF application and it takes more pixels in
    case of 120 DPI application to adjust the size properly.


  • Redefine Styles and Control Templates

    In addition to graphics and animation
    capabilities, WPF also comes with a huge flexibility to define the styles and ControlTemplates.
    Style based technique as you might come across with CSS is a set of definitions which defines how the controls
    will look like when it is rendered on the screen. In case of traditional windows applications, styles are tightly
    coupled with each control, so that you need to define color, style, etc. for each individual control to make it
    look different. In case of WPF, Styles are completely separated from the UIElement. Once you define
    a style, you can change the look and feel of any control by just putting the style on the element.

    Most of
    the UIElements that we generally deal with are actually made using more than one individual elements.
    WPF introduces a new concept of Templates, which you might use to redefine the whole control itself.
    Say for instance, you have a CheckBox, which has a Rectangle in it and a
    ContentPresenter (one where the caption of the TextBox appears). Thus you can redefine
    your checkbox and put a ToggleButton inside it, so that the check will appear on the
    ToggleButton rather than on the Rectangle. This is very interesting. We will look into
    more detail on Styles and ControlTemplates in later section of the article.



  • What is XAML?


    According to the definition, XAML is an XML based declarative markup language for specifying and setting the
    characteristics of classes. In other words, XAML is a language used by WPF, Silverlight or any other application
    which can declare classes by itself. So, you can declare a variable, define the properties of any class and
    directly use it in your application. The XAML parser will automatically parse and create the actual object
    while it renders the application.

    XAML is generally used to define layout of UI, its elements and
    objects for static and visual aspect. We cannot define flow of a program using XAML. So even though there are
    large capabilities of XAML, it is actually not a programming language, rather it is used to design UI of the
    application. Thus XAML employs other programming languages like C#, VB.NET, etc. to define the logic in code
    behind.

    ExpressionBuilder is the best tool to generate XAML.


    WPF Architecture







    For every new technology, it is very essential to have a clear idea about its architecture. So before beginning
    your application, you must grab a few concepts. If you would not like to know WPF in detail, please skip this
    section. As mentioned earlier, WPF is actually a set of assemblies that build up the entire framework. These
    assemblies can be categorized as:

    • Managed Layer
    • UnManaged Layer

    • Core API

    Managed Layer: Managed layer of WPF is built using a number of
    assemblies. These assemblies build up the WPF framework, communicate with lower level unmanaged API to render its
    content. The few assemblies that comprise the WPF framework are:

    1. PresentationFramework.
      dll
      : Creates the top level elements like layout panels, controls, windows, styles, etc.

    2. PresentationCore.dll: It holds base types such as UIElement,
      Visual from which all shapes and controls are Derived in PresentationFramework.dll.

    3. WindowsBase.dll: They hold even more basic elements which are capable of being used
      outside the WPF environment like Dispatcher object, Dependency Objects. I will discuss
      each of them later.

    Unmanaged Layer (milcore.dll): The unmanaged layer
    of WPF is called milcore or Media Integration Library Core. It basically translates the WPF higher level objects
    like layout panels, buttons, animation, etc. into textures that Direct3D expects. It is the main
    rendering engine of WPF.

    WindowsCodecs.dll: This is another low level API which
    is used for imaging support in WPF applications. WindowsCodecs.dll comprises a number of codecs which
    encode / decode images into vector graphics that would be rendered into WPF screen.

    Direct3D: It is the low level API in which the graphics of WPF is rendered.

    User32: It is the primary core API which every program uses. It actually manages memory and process separation.

    GDI & Device Drivers: GDI and Device Drivers are specific to the operating system which is also used from the application to access low level APIs.


    Building Your First WPF Application :


    Now the time has come to build your first WPF Application.
    To do this, let's open Visual Studio 2008 / 2010. For this example, I used Visual Studio 2008. Create a new
    Project. You will see a new window. The XAML will look like:

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

    <
    Window x:Class
    ="FirstWindowsApplication.Window1"
     xmlns
    ="
    http://schemas.microsoft.com/winfx/2006/xaml/presentation"

       xmlns:x
    ="http://schemas.microsoft.com/winfx/2006/xaml"
     x:Name="Window1"  
     Title="Window1" Height="300" Width="300">  
      <Grid>   
     </Grid> 
    </Window>
    *******************************************************

    Here the blank window is produced. Height / Width represents the Size of the

    Window. Title determines the text which is displayed in the TitleBar of the

    window. Every control in XAML could be named with x:Name attribute. This will

    be used to reference the Window object in your XAML. x:Class attribute

    represents the class which should be associated with current Window.

    As I already told you, that XAML is not self sufficient, so to define

    logic you need a class in C# or VB.NET.

    Grid is the primary layout for WPF application. Grid can take multiple

    Child elements. So let us put some controls into the grid.

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

    <Grid>   
     <Grid.RowDefinitions>  
    <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
    <ColumnDefinition MinWidth="50" />
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <TextBlock Text="Enter Name :" Grid.Row="0" Grid.Column="0" />
    <TextBox x:Name="txtName" Grid.Row="0" Grid.Column="1" MinWidth="50"/>
    <Button Content="Click Me" Grid.Row="0" Grid.Column="2" Click="Button_Click"/>
    </Grid>
    *******************************************************

    You can see that I have defined RowDefination and ColumnDefination.

    This allows you to divide the grid into cells so that you can place your

    control exactly where you want to. For each RowDefination and ColumnDefination,

    you can use Height and Width of it. You can see I have used 50, Auto,

    and * as width. Auto represents the size which we would define for the control

    during control definition. * indicates the rest of the space which it can

    take. Thus, you can see the button is spread the rest of the area of the

    column it finds.

    Now in the Behind, I put a Messagebox to show the content of TextBox.

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

    private void Button_Click(object sender, RoutedEventArgs e) 
     {  
        MessageBox.Show(string.Format("Hi {0}", this.txtName.Text)); 
     }
    ********************************************************************

Interview Questions Part 1


Q 1) MVC Means ?
Ans)
ASP.NET MVC is a part of the ASP.NET Web application framework
MVC stands for multi view controller and this is a part of dot net framework. It has several versions.
MVC application is created by using following 3 attributes namely: Model, View and Controller.

Model: It tells the the core information of an application which includes data, validation rules and data access and aggregation logic.

View: The view is used to encapsulate the presentation of the application.

Controller: The controller contains of the control-flow logic. Controller interacts with the Model and View in order to control the flow and execution of the application.

--------------------------------------------------------------------------------------------------------------------
Q 2) Is it possible to implement an interface to a structure?
Is it possible to extend a struct?
Is it possible to inherit a class to struct?

Is it possible to implement an interface to a structure?
Ans: A struct can implement interfaces, and it does that  exactly 
 as classes do.
Is it possible to extend a struct? 
Ans: struct cannot extend another struct  
Is it possible to inherit a class to struct?
Ans:  A struct cannot inherit from another struct or class
--------------------------------------------------------------------
Q 3)  When static constructor is invoked?
A static constructor is used to initialize any static data, or to  
perform a Particular action that needs performed once only. It is
called automatically before the first instance is created or any
static members are referenced.
Static constructors have the following properties: 
• A static constructor does not take access modifiers or have 
 parameters.
• A static constructor is called automatically to initialize the class 
 before the first instance is created or any static members are referenced.
• A static constructor cannot be called directly.
• The user has no control on when the static constructor is executed in the program.
• A typical use of static constructors is when the class is using a log file and the
  constructor is used to write entries to this file.
• Static constructors are also useful when creating wrapper classes for unmanaged
  code, when the constructor can call the LoadLibrary method.
 public class Bus {    
 // Static constructor:    
 static Bus()   
  {    
     System.Console.WriteLine("The static constructor invoked.");  
   } 
 public static void Drive()  
 {    
     System.Console.WriteLine("The Drive method invoked.");  
 }
  }  
class TestBus {     
static void Main()  
{  Bus.Drive();  
}
 }
Tags : 
MVC,
Is it possible to implement an interface to a structure,
Is it possible to extend a struct,
Is it possible to inherit a class to struct,

Is it possible to implement an interface to a structure,
 

Q 1) MVC Means ?
Ans)
ASP.NET MVC is a part of the ASP.NET Web application framework
MVC stands for multi view controller and this is a part of dot net framework. It has several versions.
MVC application is created by using following 3 attributes namely: Model, View and Controller.

Model: It tells the the core information of an application which includes data, validation rules and data access and aggregation logic.

View: The view is used to encapsulate the presentation of the application.

Controller: The controller contains of the control-flow logic. Controller interacts with the Model and View in order to control the flow and execution of the application.

--------------------------------------------------------------------------------------------------------------------
Q 2) Is it possible to implement an interface to a structure?
Is it possible to extend a struct?
Is it possible to inherit a class to struct?

Is it possible to implement an interface to a structure?
Ans: A struct can implement interfaces, and it does that  exactly 
 as classes do.
Is it possible to extend a struct? 
Ans: struct cannot extend another struct  
Is it possible to inherit a class to struct?
Ans:  A struct cannot inherit from another struct or class
--------------------------------------------------------------------
Q 3)  When static constructor is invoked?
A static constructor is used to initialize any static data, or to  
perform a Particular action that needs performed once only. It is
called automatically before the first instance is created or any
static members are referenced.
Static constructors have the following properties: 
• A static constructor does not take access modifiers or have 
 parameters.
• A static constructor is called automatically to initialize the class 
 before the first instance is created or any static members are referenced.
• A static constructor cannot be called directly.
• The user has no control on when the static constructor is executed in the program.
• A typical use of static constructors is when the class is using a log file and the
  constructor is used to write entries to this file.
• Static constructors are also useful when creating wrapper classes for unmanaged
  code, when the constructor can call the LoadLibrary method.
 public class Bus {    
 // Static constructor:    
 static Bus()   
  {    
     System.Console.WriteLine("The static constructor invoked.");  
   } 
 public static void Drive()  
 {    
     System.Console.WriteLine("The Drive method invoked.");  
 }
  }  
class TestBus {     
static void Main()  
{  Bus.Drive();  
}
 }
Tags : 
MVC,
Is it possible to implement an interface to a structure,
Is it possible to extend a struct,
Is it possible to inherit a class to struct,

Is it possible to implement an interface to a structure,
 

Interview Questions Part 1


Q 1) MVC Means ?
Ans)
ASP.NET MVC is a part of the ASP.NET Web application framework
MVC stands for multi view controller and this is a part of dot net framework. It has several versions.
MVC application is created by using following 3 attributes namely: Model, View and Controller.

Model: It tells the the core information of an application which includes data, validation rules and data access and aggregation logic.

View: The view is used to encapsulate the presentation of the application.

Controller: The controller contains of the control-flow logic. Controller interacts with the Model and View in order to control the flow and execution of the application.

--------------------------------------------------------------------------------------------------------------------
Q 2) Is it possible to implement an interface to a structure?
Is it possible to extend a struct?
Is it possible to inherit a class to struct?

Is it possible to implement an interface to a structure?
Ans: A struct can implement interfaces, and it does that  exactly 
 as classes do.
Is it possible to extend a struct? 
Ans: struct cannot extend another struct  
Is it possible to inherit a class to struct?
Ans:  A struct cannot inherit from another struct or class
--------------------------------------------------------------------
Q 3)  When static constructor is invoked?
A static constructor is used to initialize any static data, or to  
perform a Particular action that needs performed once only. It is
called automatically before the first instance is created or any
static members are referenced.
Static constructors have the following properties: 
• A static constructor does not take access modifiers or have 
 parameters.
• A static constructor is called automatically to initialize the class 
 before the first instance is created or any static members are referenced.
• A static constructor cannot be called directly.
• The user has no control on when the static constructor is executed in the program.
• A typical use of static constructors is when the class is using a log file and the
  constructor is used to write entries to this file.
• Static constructors are also useful when creating wrapper classes for unmanaged
  code, when the constructor can call the LoadLibrary method.
 public class Bus {    
 // Static constructor:    
 static Bus()   
  {    
     System.Console.WriteLine("The static constructor invoked.");  
   } 
 public static void Drive()  
 {    
     System.Console.WriteLine("The Drive method invoked.");  
 }
  }  
class TestBus {     
static void Main()  
{  Bus.Drive();  
}
 }
Tags : 
MVC,
Is it possible to implement an interface to a structure,
Is it possible to extend a struct,
Is it possible to inherit a class to struct,

Is it possible to implement an interface to a structure,
 

Q 1) MVC Means ?
Ans)
ASP.NET MVC is a part of the ASP.NET Web application framework
MVC stands for multi view controller and this is a part of dot net framework. It has several versions.
MVC application is created by using following 3 attributes namely: Model, View and Controller.

Model: It tells the the core information of an application which includes data, validation rules and data access and aggregation logic.

View: The view is used to encapsulate the presentation of the application.

Controller: The controller contains of the control-flow logic. Controller interacts with the Model and View in order to control the flow and execution of the application.

--------------------------------------------------------------------------------------------------------------------
Q 2) Is it possible to implement an interface to a structure?
Is it possible to extend a struct?
Is it possible to inherit a class to struct?

Is it possible to implement an interface to a structure?
Ans: A struct can implement interfaces, and it does that  exactly 
 as classes do.
Is it possible to extend a struct? 
Ans: struct cannot extend another struct  
Is it possible to inherit a class to struct?
Ans:  A struct cannot inherit from another struct or class
--------------------------------------------------------------------
Q 3)  When static constructor is invoked?
A static constructor is used to initialize any static data, or to  
perform a Particular action that needs performed once only. It is
called automatically before the first instance is created or any
static members are referenced.
Static constructors have the following properties: 
• A static constructor does not take access modifiers or have 
 parameters.
• A static constructor is called automatically to initialize the class 
 before the first instance is created or any static members are referenced.
• A static constructor cannot be called directly.
• The user has no control on when the static constructor is executed in the program.
• A typical use of static constructors is when the class is using a log file and the
  constructor is used to write entries to this file.
• Static constructors are also useful when creating wrapper classes for unmanaged
  code, when the constructor can call the LoadLibrary method.
 public class Bus {    
 // Static constructor:    
 static Bus()   
  {    
     System.Console.WriteLine("The static constructor invoked.");  
   } 
 public static void Drive()  
 {    
     System.Console.WriteLine("The Drive method invoked.");  
 }
  }  
class TestBus {     
static void Main()  
{  Bus.Drive();  
}
 }
Tags : 
MVC,
Is it possible to implement an interface to a structure,
Is it possible to extend a struct,
Is it possible to inherit a class to struct,

Is it possible to implement an interface to a structure,
 

Getting column values as comma seperated list using XML PATH()



select tc.customerid,stuff((
select ',' + convert(nvarchar(30),tct.Customer_TripId)
from tollplus.TP_Customers tc
inner join tollplus.TP_Customer_Trips tct
on tc.customerid=tct.customerid and tc.customerid=60000252
for xml path('')),1,1,'')as usergroups
from tollplus.TP_Customers tc where tc.customerid=60000252




select tc.customerid,stuff((
select ',' + convert(nvarchar(30),tct.Customer_TripId)
from tollplus.TP_Customers tc
inner join tollplus.TP_Customer_Trips tct
on tc.customerid=tct.customerid and tc.customerid=60000252
for xml path('')),1,1,'')as usergroups
from tollplus.TP_Customers tc where tc.customerid=60000252


Getting column values as comma seperated list using XML PATH()



select tc.customerid,stuff((
select ',' + convert(nvarchar(30),tct.Customer_TripId)
from tollplus.TP_Customers tc
inner join tollplus.TP_Customer_Trips tct
on tc.customerid=tct.customerid and tc.customerid=60000252
for xml path('')),1,1,'')as usergroups
from tollplus.TP_Customers tc where tc.customerid=60000252




select tc.customerid,stuff((
select ',' + convert(nvarchar(30),tct.Customer_TripId)
from tollplus.TP_Customers tc
inner join tollplus.TP_Customer_Trips tct
on tc.customerid=tct.customerid and tc.customerid=60000252
for xml path('')),1,1,'')as usergroups
from tollplus.TP_Customers tc where tc.customerid=60000252


SqlServer - Ordering result set with null values after non-null values


Order by with null values in sql server is a tricky. Normally it puts the result set like: NULL, NULL, 1,2,3...etc

If your want the result set like: 1,2,3,NULL, NULL,......etc there is not direct method for this. You have to use the below script to get the required output.


declare @MaxId int
select @MaxId = max(code) + 1 FROM TableA

SELECT code
FROM TableA
ORDER by isnull(code, @MaxId)

Order by with null values in sql server is a tricky. Normally it puts the result set like: NULL, NULL, 1,2,3...etc

If your want the result set like: 1,2,3,NULL, NULL,......etc there is not direct method for this. You have to use the below script to get the required output.


declare @MaxId int
select @MaxId = max(code) + 1 FROM TableA

SELECT code
FROM TableA
ORDER by isnull(code, @MaxId)

SqlServer - Ordering result set with null values after non-null values


Order by with null values in sql server is a tricky. Normally it puts the result set like: NULL, NULL, 1,2,3...etc

If your want the result set like: 1,2,3,NULL, NULL,......etc there is not direct method for this. You have to use the below script to get the required output.


declare @MaxId int
select @MaxId = max(code) + 1 FROM TableA

SELECT code
FROM TableA
ORDER by isnull(code, @MaxId)

Order by with null values in sql server is a tricky. Normally it puts the result set like: NULL, NULL, 1,2,3...etc

If your want the result set like: 1,2,3,NULL, NULL,......etc there is not direct method for this. You have to use the below script to get the required output.


declare @MaxId int
select @MaxId = max(code) + 1 FROM TableA

SELECT code
FROM TableA
ORDER by isnull(code, @MaxId)

Sql Server 2008 Installation Process

For Sql server 2008 Installation Process.

Check the below URL to get the Clear Information.

http://www.sqlcoffee.com/SQLServer2008_0011.htm
For Sql server 2008 Installation Process.

Check the below URL to get the Clear Information.

http://www.sqlcoffee.com/SQLServer2008_0011.htm

Sql Server 2008 Installation Process

For Sql server 2008 Installation Process.

Check the below URL to get the Clear Information.

http://www.sqlcoffee.com/SQLServer2008_0011.htm
For Sql server 2008 Installation Process.

Check the below URL to get the Clear Information.

http://www.sqlcoffee.com/SQLServer2008_0011.htm

Filter data by using IN and NOT IN clause

In this post I am going to show some SQLqueries and LINQ queries, but not going to show images for all cases.Filter data by using IN and NOT IN clause

Most of the developer who started working on LINQ queries gets confuse when they got requirement to write IN and NOT IN query using LINQ.


SQL Query
//IN
SELECT [Id], [UserId], [IMEINo]
FROM [UserClients]
WHERE [UserId] IN (3, 4)

or

//NOT IN
SELECT [Id], [UserId], [IMEINo]
FROM [UserClients]
WHERE [UserId] IN (3, 4)

as you see above query use IN and NOT IN clause to filter from list of records.

LINQ Query
To achieve similar task LINQ make use of Contains function of C#. which do filtering of record form the list of record.

//IN
int[] chosenOnes = { 3, 4 };
var user = from u in UserClients
where chosenOnes.Contains(u.UserId.Value)
select new { u.id,u.userid, u.ImeiNo};

or

//NOT IN
int[] chosenOnes = { 3, 4 };
var user = from u in UserClients
where !chosenOnes.Contains(u.UserId.Value)
select u;

Note :
IN and NOT IN use same function in LINQ query but it just use !(Not) symbol for it
In this post I am going to show some SQLqueries and LINQ queries, but not going to show images for all cases.Filter data by using IN and NOT IN clause

Most of the developer who started working on LINQ queries gets confuse when they got requirement to write IN and NOT IN query using LINQ.


SQL Query
//IN
SELECT [Id], [UserId], [IMEINo]
FROM [UserClients]
WHERE [UserId] IN (3, 4)

or

//NOT IN
SELECT [Id], [UserId], [IMEINo]
FROM [UserClients]
WHERE [UserId] IN (3, 4)

as you see above query use IN and NOT IN clause to filter from list of records.

LINQ Query
To achieve similar task LINQ make use of Contains function of C#. which do filtering of record form the list of record.

//IN
int[] chosenOnes = { 3, 4 };
var user = from u in UserClients
where chosenOnes.Contains(u.UserId.Value)
select new { u.id,u.userid, u.ImeiNo};

or

//NOT IN
int[] chosenOnes = { 3, 4 };
var user = from u in UserClients
where !chosenOnes.Contains(u.UserId.Value)
select u;

Note :
IN and NOT IN use same function in LINQ query but it just use !(Not) symbol for it

Filter data by using IN and NOT IN clause

In this post I am going to show some SQLqueries and LINQ queries, but not going to show images for all cases.Filter data by using IN and NOT IN clause

Most of the developer who started working on LINQ queries gets confuse when they got requirement to write IN and NOT IN query using LINQ.


SQL Query
//IN
SELECT [Id], [UserId], [IMEINo]
FROM [UserClients]
WHERE [UserId] IN (3, 4)

or

//NOT IN
SELECT [Id], [UserId], [IMEINo]
FROM [UserClients]
WHERE [UserId] IN (3, 4)

as you see above query use IN and NOT IN clause to filter from list of records.

LINQ Query
To achieve similar task LINQ make use of Contains function of C#. which do filtering of record form the list of record.

//IN
int[] chosenOnes = { 3, 4 };
var user = from u in UserClients
where chosenOnes.Contains(u.UserId.Value)
select new { u.id,u.userid, u.ImeiNo};

or

//NOT IN
int[] chosenOnes = { 3, 4 };
var user = from u in UserClients
where !chosenOnes.Contains(u.UserId.Value)
select u;

Note :
IN and NOT IN use same function in LINQ query but it just use !(Not) symbol for it
In this post I am going to show some SQLqueries and LINQ queries, but not going to show images for all cases.Filter data by using IN and NOT IN clause

Most of the developer who started working on LINQ queries gets confuse when they got requirement to write IN and NOT IN query using LINQ.


SQL Query
//IN
SELECT [Id], [UserId], [IMEINo]
FROM [UserClients]
WHERE [UserId] IN (3, 4)

or

//NOT IN
SELECT [Id], [UserId], [IMEINo]
FROM [UserClients]
WHERE [UserId] IN (3, 4)

as you see above query use IN and NOT IN clause to filter from list of records.

LINQ Query
To achieve similar task LINQ make use of Contains function of C#. which do filtering of record form the list of record.

//IN
int[] chosenOnes = { 3, 4 };
var user = from u in UserClients
where chosenOnes.Contains(u.UserId.Value)
select new { u.id,u.userid, u.ImeiNo};

or

//NOT IN
int[] chosenOnes = { 3, 4 };
var user = from u in UserClients
where !chosenOnes.Contains(u.UserId.Value)
select u;

Note :
IN and NOT IN use same function in LINQ query but it just use !(Not) symbol for it

Linq to get the values with Comma seperated.

Here is the LINQ to convert your LINQ result into a comma separated value:

string returnVal = (from a in b
select a.StringValue).Aggregate(new StringBuilder(),
(c, d) => c.Append(",").Append(@"""" + d + @""""),
(c) => c.ToString().TrimStart(new char[] { ',' })
.TrimEnd(new char[] { ',' }))

Example:


customerTrips = (from a in dtReceiptAmountDetails.AsEnumerable()
select a.Field("Customer_TripId").ToString()).Aggregate(new StringBuilder(),
(c, d) => c.Append(",").Append(d),
(c) => c.ToString().TrimStart(new char[] { ',' })
.TrimEnd(new char[] { ',' }));

dtReceiptAmountDetails ---> Data Table
Customer_TripId ---> Column Name.

Here is the LINQ to convert your LINQ result into a comma separated value:

string returnVal = (from a in b
select a.StringValue).Aggregate(new StringBuilder(),
(c, d) => c.Append(",").Append(@"""" + d + @""""),
(c) => c.ToString().TrimStart(new char[] { ',' })
.TrimEnd(new char[] { ',' }))

Example:


customerTrips = (from a in dtReceiptAmountDetails.AsEnumerable()
select a.Field("Customer_TripId").ToString()).Aggregate(new StringBuilder(),
(c, d) => c.Append(",").Append(d),
(c) => c.ToString().TrimStart(new char[] { ',' })
.TrimEnd(new char[] { ',' }));

dtReceiptAmountDetails ---> Data Table
Customer_TripId ---> Column Name.

Linq to get the values with Comma seperated.

Here is the LINQ to convert your LINQ result into a comma separated value:

string returnVal = (from a in b
select a.StringValue).Aggregate(new StringBuilder(),
(c, d) => c.Append(",").Append(@"""" + d + @""""),
(c) => c.ToString().TrimStart(new char[] { ',' })
.TrimEnd(new char[] { ',' }))

Example:


customerTrips = (from a in dtReceiptAmountDetails.AsEnumerable()
select a.Field("Customer_TripId").ToString()).Aggregate(new StringBuilder(),
(c, d) => c.Append(",").Append(d),
(c) => c.ToString().TrimStart(new char[] { ',' })
.TrimEnd(new char[] { ',' }));

dtReceiptAmountDetails ---> Data Table
Customer_TripId ---> Column Name.

Here is the LINQ to convert your LINQ result into a comma separated value:

string returnVal = (from a in b
select a.StringValue).Aggregate(new StringBuilder(),
(c, d) => c.Append(",").Append(@"""" + d + @""""),
(c) => c.ToString().TrimStart(new char[] { ',' })
.TrimEnd(new char[] { ',' }))

Example:


customerTrips = (from a in dtReceiptAmountDetails.AsEnumerable()
select a.Field("Customer_TripId").ToString()).Aggregate(new StringBuilder(),
(c, d) => c.Append(",").Append(d),
(c) => c.ToString().TrimStart(new char[] { ',' })
.TrimEnd(new char[] { ',' }));

dtReceiptAmountDetails ---> Data Table
Customer_TripId ---> Column Name.

Difference between VS2008 & VS2010

  1. Project Solution Extension in vs2008 is ".sln(Solution)"
  2. Project Solution Extension in vs2010 is " .suo(Solution User Options) "
  1. Project Solution Extension in vs2008 is ".sln(Solution)"
  2. Project Solution Extension in vs2010 is " .suo(Solution User Options) "

Difference between VS2008 & VS2010

  1. Project Solution Extension in vs2008 is ".sln(Solution)"
  2. Project Solution Extension in vs2010 is " .suo(Solution User Options) "
  1. Project Solution Extension in vs2008 is ".sln(Solution)"
  2. Project Solution Extension in vs2010 is " .suo(Solution User Options) "

Sql Server 2000,2005 & 2008 Version differences

I mention the the difference between all the sql server version difference Point's wise to understand easily.

Sql Server 2000:

1.Query Analyser and Enterprise manager are separate.
2.No XML datatype is used.
3.We can create maximum of 65,535 databases.
4.Nill
5.Nill
6.Nill
7.Nill
8.Nill
9.Nill
10.Nill
11.Nill
12.Nill
13.cant compress the tables and indexes.
14.Datetime datatype is used for both date and time.
15.No varchar(max) or varbinary(max) is available.
16.No table datatype is included.
17.No SSIS is included.
18.CMS is not available.
19.PBM is not available.

Sql Server 2005:

1.Both are combined as SSMS(Sql Server management Studio).
2.XML datatype is introduced.
3.We can create 2(pow(20))-1 databases.
4.Exception Handling
5.Varchar(Max) data type
6.DDL Triggers
7.DataBase Mirroring
8.RowNumber function for paging
9.Table fragmentation
10.Full Text Search
11.Bulk Copy Update
12.Cant encrypt
13.Can Compress tables and indexes.(Introduced in 2005 SP2)
14.Datetime is used for both date and time.
15.Varchar(max) and varbinary(max) is used.
16.No table datatype is included.
17.SSIS is started using.
18.CMS is not available.
19.PBM is not available.


Sql Server 2008:

1.Both are combined as SSMS(Sql Server management Studio).
2.XML datatype is used.
3.We can create 2(pow(20))-1 databases.
4.Exception Handling
5.Varchar(Max) data type
6.DDL Triggers
7.DataBase Mirroring
8.RowNumber function for paging
9.Table fragmentation
10.Full Text Search
11.Bulk Copy Update
12.Can encrypt the entire database introduced in 2008.
13.Can compress tables and indexes.
14.Date and time are seperately used for date and time datatype,geospatial and timestamp with internal timezone is used.
15.Varchar(max) and varbinary(max) is used.
16.Table datatype introduced.
17.SSIS avails in this version.
18.Central Management Server(CMS) is Introduced.
19.Policy based management(PBM) server is Introduced.


I mention the the difference between all the sql server version difference Point's wise to understand easily.

Sql Server 2000:

1.Query Analyser and Enterprise manager are separate.
2.No XML datatype is used.
3.We can create maximum of 65,535 databases.
4.Nill
5.Nill
6.Nill
7.Nill
8.Nill
9.Nill
10.Nill
11.Nill
12.Nill
13.cant compress the tables and indexes.
14.Datetime datatype is used for both date and time.
15.No varchar(max) or varbinary(max) is available.
16.No table datatype is included.
17.No SSIS is included.
18.CMS is not available.
19.PBM is not available.

Sql Server 2005:

1.Both are combined as SSMS(Sql Server management Studio).
2.XML datatype is introduced.
3.We can create 2(pow(20))-1 databases.
4.Exception Handling
5.Varchar(Max) data type
6.DDL Triggers
7.DataBase Mirroring
8.RowNumber function for paging
9.Table fragmentation
10.Full Text Search
11.Bulk Copy Update
12.Cant encrypt
13.Can Compress tables and indexes.(Introduced in 2005 SP2)
14.Datetime is used for both date and time.
15.Varchar(max) and varbinary(max) is used.
16.No table datatype is included.
17.SSIS is started using.
18.CMS is not available.
19.PBM is not available.


Sql Server 2008:

1.Both are combined as SSMS(Sql Server management Studio).
2.XML datatype is used.
3.We can create 2(pow(20))-1 databases.
4.Exception Handling
5.Varchar(Max) data type
6.DDL Triggers
7.DataBase Mirroring
8.RowNumber function for paging
9.Table fragmentation
10.Full Text Search
11.Bulk Copy Update
12.Can encrypt the entire database introduced in 2008.
13.Can compress tables and indexes.
14.Date and time are seperately used for date and time datatype,geospatial and timestamp with internal timezone is used.
15.Varchar(max) and varbinary(max) is used.
16.Table datatype introduced.
17.SSIS avails in this version.
18.Central Management Server(CMS) is Introduced.
19.Policy based management(PBM) server is Introduced.


Sql Server 2000,2005 & 2008 Version differences

I mention the the difference between all the sql server version difference Point's wise to understand easily.

Sql Server 2000:

1.Query Analyser and Enterprise manager are separate.
2.No XML datatype is used.
3.We can create maximum of 65,535 databases.
4.Nill
5.Nill
6.Nill
7.Nill
8.Nill
9.Nill
10.Nill
11.Nill
12.Nill
13.cant compress the tables and indexes.
14.Datetime datatype is used for both date and time.
15.No varchar(max) or varbinary(max) is available.
16.No table datatype is included.
17.No SSIS is included.
18.CMS is not available.
19.PBM is not available.

Sql Server 2005:

1.Both are combined as SSMS(Sql Server management Studio).
2.XML datatype is introduced.
3.We can create 2(pow(20))-1 databases.
4.Exception Handling
5.Varchar(Max) data type
6.DDL Triggers
7.DataBase Mirroring
8.RowNumber function for paging
9.Table fragmentation
10.Full Text Search
11.Bulk Copy Update
12.Cant encrypt
13.Can Compress tables and indexes.(Introduced in 2005 SP2)
14.Datetime is used for both date and time.
15.Varchar(max) and varbinary(max) is used.
16.No table datatype is included.
17.SSIS is started using.
18.CMS is not available.
19.PBM is not available.


Sql Server 2008:

1.Both are combined as SSMS(Sql Server management Studio).
2.XML datatype is used.
3.We can create 2(pow(20))-1 databases.
4.Exception Handling
5.Varchar(Max) data type
6.DDL Triggers
7.DataBase Mirroring
8.RowNumber function for paging
9.Table fragmentation
10.Full Text Search
11.Bulk Copy Update
12.Can encrypt the entire database introduced in 2008.
13.Can compress tables and indexes.
14.Date and time are seperately used for date and time datatype,geospatial and timestamp with internal timezone is used.
15.Varchar(max) and varbinary(max) is used.
16.Table datatype introduced.
17.SSIS avails in this version.
18.Central Management Server(CMS) is Introduced.
19.Policy based management(PBM) server is Introduced.


I mention the the difference between all the sql server version difference Point's wise to understand easily.

Sql Server 2000:

1.Query Analyser and Enterprise manager are separate.
2.No XML datatype is used.
3.We can create maximum of 65,535 databases.
4.Nill
5.Nill
6.Nill
7.Nill
8.Nill
9.Nill
10.Nill
11.Nill
12.Nill
13.cant compress the tables and indexes.
14.Datetime datatype is used for both date and time.
15.No varchar(max) or varbinary(max) is available.
16.No table datatype is included.
17.No SSIS is included.
18.CMS is not available.
19.PBM is not available.

Sql Server 2005:

1.Both are combined as SSMS(Sql Server management Studio).
2.XML datatype is introduced.
3.We can create 2(pow(20))-1 databases.
4.Exception Handling
5.Varchar(Max) data type
6.DDL Triggers
7.DataBase Mirroring
8.RowNumber function for paging
9.Table fragmentation
10.Full Text Search
11.Bulk Copy Update
12.Cant encrypt
13.Can Compress tables and indexes.(Introduced in 2005 SP2)
14.Datetime is used for both date and time.
15.Varchar(max) and varbinary(max) is used.
16.No table datatype is included.
17.SSIS is started using.
18.CMS is not available.
19.PBM is not available.


Sql Server 2008:

1.Both are combined as SSMS(Sql Server management Studio).
2.XML datatype is used.
3.We can create 2(pow(20))-1 databases.
4.Exception Handling
5.Varchar(Max) data type
6.DDL Triggers
7.DataBase Mirroring
8.RowNumber function for paging
9.Table fragmentation
10.Full Text Search
11.Bulk Copy Update
12.Can encrypt the entire database introduced in 2008.
13.Can compress tables and indexes.
14.Date and time are seperately used for date and time datatype,geospatial and timestamp with internal timezone is used.
15.Varchar(max) and varbinary(max) is used.
16.Table datatype introduced.
17.SSIS avails in this version.
18.Central Management Server(CMS) is Introduced.
19.Policy based management(PBM) server is Introduced.


Linq concepts

Linq Sum :

If we want to implement the Linq Concepts must use "Systme.Linq" reference
(using System.Linq;)

Example with Description:
decimal lineItems_SUM = 0;

lineItems_SUM = (from "AliasName" in "IList Items" // List items.

select
"AliasName"."Property" ).Sum();


Linq Sum :

If we want to implement the Linq Concepts must use "Systme.Linq" reference
(using System.Linq;)

Example with Description:
decimal lineItems_SUM = 0;

lineItems_SUM = (from "AliasName" in "IList Items" // List items.

select
"AliasName"."Property" ).Sum();


Linq concepts

Linq Sum :

If we want to implement the Linq Concepts must use "Systme.Linq" reference
(using System.Linq;)

Example with Description:
decimal lineItems_SUM = 0;

lineItems_SUM = (from "AliasName" in "IList Items" // List items.

select
"AliasName"."Property" ).Sum();


Linq Sum :

If we want to implement the Linq Concepts must use "Systme.Linq" reference
(using System.Linq;)

Example with Description:
decimal lineItems_SUM = 0;

lineItems_SUM = (from "AliasName" in "IList Items" // List items.

select
"AliasName"."Property" ).Sum();


Asp Controls Rendering.

Example with an Asp Button Control.

In Asp:

asp:Button ID="btnCancel" runat="server" Text="CANCEL" ToolTip="Cancel" CssClass="submitbtn" TabIndex="9"


After Rendering:
 <input type="submit"
name="ctl00$ContentPlaceHolder1$ctl00$btnCancel"
value="CANCEL" id="ctl00_ContentPlaceHolder1_ctl00_btnCancel"
tabindex="9" title="Cancel" class="submitbtn" />


Description:

Ofcourse almost we know except "name" After Rendering.
name -- This is used to maintain the view state.
If we want to find the button using view state using the "name"
tag we can identified.

Example with an Asp Button Control.

In Asp:

asp:Button ID="btnCancel" runat="server" Text="CANCEL" ToolTip="Cancel" CssClass="submitbtn" TabIndex="9"


After Rendering:
 <input type="submit"
name="ctl00$ContentPlaceHolder1$ctl00$btnCancel"
value="CANCEL" id="ctl00_ContentPlaceHolder1_ctl00_btnCancel"
tabindex="9" title="Cancel" class="submitbtn" />


Description:

Ofcourse almost we know except "name" After Rendering.
name -- This is used to maintain the view state.
If we want to find the button using view state using the "name"
tag we can identified.

Asp Controls Rendering.

Example with an Asp Button Control.

In Asp:

asp:Button ID="btnCancel" runat="server" Text="CANCEL" ToolTip="Cancel" CssClass="submitbtn" TabIndex="9"


After Rendering:
 <input type="submit"
name="ctl00$ContentPlaceHolder1$ctl00$btnCancel"
value="CANCEL" id="ctl00_ContentPlaceHolder1_ctl00_btnCancel"
tabindex="9" title="Cancel" class="submitbtn" />


Description:

Ofcourse almost we know except "name" After Rendering.
name -- This is used to maintain the view state.
If we want to find the button using view state using the "name"
tag we can identified.

Example with an Asp Button Control.

In Asp:

asp:Button ID="btnCancel" runat="server" Text="CANCEL" ToolTip="Cancel" CssClass="submitbtn" TabIndex="9"


After Rendering:
 <input type="submit"
name="ctl00$ContentPlaceHolder1$ctl00$btnCancel"
value="CANCEL" id="ctl00_ContentPlaceHolder1_ctl00_btnCancel"
tabindex="9" title="Cancel" class="submitbtn" />


Description:

Ofcourse almost we know except "name" After Rendering.
name -- This is used to maintain the view state.
If we want to find the button using view state using the "name"
tag we can identified.

This Fry is latest and taste always

This Fry is latest and taste always
This Fry is latest and taste always

This Fry is latest and taste always

This Fry is latest and taste always
This Fry is latest and taste always