LINQ tutorial Part -Ist

1. What is Linq ?

Ans :- LINQ is stands for Language Integrated Query.Its new set of technologies which provide simple statement like sql. On any object.

This just like simple Sql statements. Linq can be operational on Object, SQL and XML.

LINQ TO Object :- Linq to object allow you to query on collection of objects like array

LINQ To Sql :- by the name its clear that it will work on Data.With help on ORM we can use data to manipulate and access the data.

LINQ To XML :-One of the most important feature of linq is that it can be operational on XML too. With the help of this we can use XML in easy way for read & Write Operation.

2. Linq Operations :-

Linq is such utility which can be used by programmer in very easy way. There are many operation which we can use like select data, conditional selection, sum, average other operation can be perform on object with linq. All be below operation is applied on Sql & XML also.

Here I am with a array on which we do linq operation

Dim ah As Integer() = {10, 4, 6, 20, 55, 22, 1, 40, 66, 69, 77, 24, 20, 10, 33}

1) Simple Select :- it will return all the element of array

Ex:- dim lnq = from a in ah select a

2) Where clause :- The where clause work in below manner


Dim lnq = From a In ah Where a < 20 Order By a

With this we can find array element which is less then 20

Dim lnq = From a In ah Where a Mod 2 = 0 Order By a

with this statement we get element only which is fully divisible by 2

Dim lnq = From a In ah Where a = 66

With this we get only value 66

3) And clause :-

Ex:- Dim lnq = From a In ah Where a >= 30 And a <= 69 Order By a

with this we can get only those element which is in the range of 30 & 69

4) Or clause :-

Ex- Dim lnq = From a In ah Where a >= 30 Or a Mod 2 = 0 Order By a

With this we can get element in or condition means either element may be greater than 30 or modules with 2 will be 0.

5) Take clause :- take (number) with this we can get particular number of element from array which we specify


Dim lnq = From a In ah Select a Take 3 Order By a Descending

With this element we can get starting 3 element in array

6)Take With while condition :-

This is same the take clause means it also get selected element but only one thing is here up to which condition is true


Dim lnq = From a In ah Take While a Mod 2 = 0

This will take all the starting element from array whose modules 2 is zero if it breaks after 2 element then take statement terminate.

7) Skip:- It is just opposit to take it . It skip the number of elements from starting position as assign.


Dim lnq = From a In ah Skip 3

This will skip first 3 element from array

8) Skip with While:- It Will skip the element up to true condition

Ex:- Dim lnq = From a In ah Skip While a Mod 2 = 0

This will skip all the starting element from array whose modules 2 is zero.

9) Order by:- if we want to order by the linq then we can do this by order by. By default its ascending which can be change by writing descending after oder by if we want to oder by on second criteria using ThenBy we can use.


10) Reverse clause:- Reverse It reverse the selected records from linq


Dim lnq = (From a In ah Select a).Reverse()

it give us revese array elements

11) Distinct clause :-

Distinct operation give us distict element from linq.

Ex:- Dim lnq = From a In ah Select a Distinct

This will give distict element from array.

12) First clause :-First Clause give you first element of the linq.
Ex:-Dim lnq = (From a In ah Select a).First()
it Will give first element of the array.
13) Last clause :-

Its just opposite to first clause it will give last element of the linq.

Ex:-Dim lnq = (From a In ah Select a).Last()
it will give the last element of the array.

14) FirstOrDefault :-

if there is no value in selection then it will return the default value other wise it will return first Element.


Dim lnq = (From a In ah Select a).FirstOrDefault()

it Will give first element of the array.

15) LastOrDefault :-

if there is no value in selection then it will return the default value otherewise it will return the last element.


Dim lnq = (From a In ah Select a).LastOrDefault()

it Will give Last element of the array and if array don’t have any value then it will return zero.

16) ElementAt Clause :-

Element At particular index position & elementAtDeafult(position)


Dim lnq = (From a In ah Select a).ElementAt(16)

it will return element at index position 16

17) Count :-

It will give the number of element selected by linq.

Ex:-Dim lnq = (From a In ah Select a).Count()
18)Sum :- It will give sum of linq element.
Ex:-Dim lnq = (From a In ah Select a).Sum() 
19) Min:- It will return minimum from linq.
Ex:-Dim lnq = (From a In ah Select a).Min()
20) Max:-It will return from max from linq
Ex:-Dim lnq = (From a In ah Select a).Max()
21) Average :- it will give the average from linq .
Ex:-Dim lnq = (From a In ah Select a).Average()
Rest will be in next post.



JQuery a unique thing part- IV

Hello friends,

Today i am with new topic which is Jquery  and ajax. which is most intresting topic of mine  i am here with some basic fuction  so enjoy with this.

Ajax Functionality & JQuery


Jquery is giving many function for using ajax which help to use ajax functionality easy. Here we goes with detail

$.ajax (s) :- its first and basic function for using ajax by Jquery.

Where s I can it collection of different properties which is enclosed in curly brackets “{ }”

1) $.ajax( {type : ” GET/POST”,

url : ” any url” ,

data : “data1=rajat& data2=test”, ( any data which you want to pass to the server…)

Success: function () {} , (any operation after successful readystate= 4)

cache : “TRUE/FALSE” ,


Ex:- To pass data from client to server we use following example


type: “POST”,

url: “SaveUser.aspx”,

data: “name=RAJAT&Surname=JAISWAL”,

success: function(msg){

alert( “Data Saved: ” + msg );


} );

2)load(url) :- by the name it is clear that it will load html of a remote file and inject in current calling element.

Ex:- $(“#dvResult”).load(“htmlPage1.htm”);

it will load htmlPage1.htm ‘s html in div part

3) $.get(url) :- Simplest form to use http get request is $.get which is jquery.get(). We can send data along with this also which is optional part.

EX:- $(“save.aspx”,{name:”RAJAT”, surname:”JAISWAL”});

suppose if want to take back result from Response. Then it has following format $(“save.aspx”,{name:”RAJAT”, surname: “JAISWAL”} , function(data) { alert(‘do operation’ + data);});

4)$.getJASON(url,data,function) :- To get response in json format we use this fuction its same as $get the diffrence here is only one that its respond in Json.

Ex- suppose from server the data return in json format which is { “info”:[{ “strFirstName” :”Rajat” , “strLastName” : “Jaiswal”}]}

Then we do below code $.getJSON(“default.aspx”, function(data) { alert([0].strFirstName +[0].strLastName); });

5) $.post(url,data,function):- it same as get method just a diffrence that it use post method to send data.

Ex:- $.post(“save.aspx”);

In next session i will come with simple example related to Ajax & Jquery.



AJAX Basic Part – III


today we will do next  topic so lets begin

5. What is JSON ?
Ans: JSON is JavaScript Object Notation. It’s a light weight Data interchange format which is independent from language. Its easy to read & Write by human & easy to parse & genrate by language. The attributes is seprated with “,” (comma) and value of attributes are define after colon symbol(“:”) .
Ex:- {Data:[{“fname” : “RAJAT”, “Lname” : “JAISWAL” }]}
The above is JSON example in which there are two attributes fname, Lname and the are seprated by “,” (comma) symbol.
And there value is “RAJAT” & JAISWAL” which are define after “:” (colon) symbol.
I am attaching  project file just go through it.

One of the most important work here is to parse json

We do response with following format




 {“Bank”:[{“lngId” : “1”, “strCode” :”ICICI” ,”strBank” : “ICICI BANK” },{“lngId” : “2”, “strCode” :”HDFC” ,”strBank” : “HDFC BANK” }]}

 When we parse with json then here is the code for it.

  function myServerResponse() {
            if (myServerRequest.readyState == 4) {
                if (myServerRequest.status == 200) {
                    var tdata;
                    tdata = eval(‘(‘+ myServerRequest.responseText +’)’);
                    var intI;
                    intI = 0;
                    var strResult =”<table border=’1′ cellspacing=’4′ cellpadding=’5′><TR><TD>lngId</td><td>code</td><td>Bank</td></tr>”
                    for (intI = 0; intI <= – 1; intI++) {
                      strResult = strResult + “<tr><td>” +[intI].lngId + “</td><td>” +[intI].strCode + “</td><td>” +[intI].strBank + “</td></tr>”;
                    strResult = strResult + “</table>”
                    document.getElementById(‘dvResult’).innerHTML = strResult;
                } else {
            return false;


 Here we first eval the responseText then  we just use it as collection array as shown in above example.[0].lngId = 1[0].strCode =”ICICI”[0].strBank =”ICICI BANK”

in the above manner we use the Json which is meaning ful and simple format.

for more information check out the attached project. bankmasterProject



JQuery a unique thing part- III

Hello friends,

today i am with new topic of jQuery which is events.  after this we will work on   Jquery + AJAX  & Jquery + 3.5  so bear with me on events. here we goes.

Ans: Jquery event system is normalize the event object.Then event object is guranteed to be passed in event handler.

Here is more description

1) event.type :- Determine the nature of event.

Ex:- $(a).click(function(event) { alert(event.type);}); it will return “click”

2) Give the refrence of DOM element which raised the event.

EX:- $(a).click(function(event){alert(;});

Return the url which is assign to a for href property.

3)event.pageX/pageY: – return the mouse position (cordinate) relative to the document.

Ex:- $(a).click(function (event){ alert(event.PageX); alert(event.PageY); });

4) event.preventDefault() :-

it will stop the default exceution action.

EX:- $(a).click(function(event) { event.preventDefault(); alert(‘test’);}); stop the a href ( transfer to another page)

The above are the basic for event object.

5) ready :- On of the most and basic event for Jquery is ready().

It bind the function to be executed when ever the document is ready for traverse and mainupulate.

Its base of jquery it improve web performance as well.

You many have as many as ready event in your web form. It will execute in the order as you define the events. It’s a solid replacment of window.load()

6) Bind() :- Suppose you have more than one paragraph and you want same event on each paragraph then instead of writing each paragraph can bind paragraph with particular event.

Ex:- $(“p”).bind(“onmouseover”, function (){ $(this).css(“background- color”,”red”);});

7)One() :- suppose we want a event only once on the document then we can bind the event by one.

Then it will run only once on the particular event.

Ex:- suppose we want click event only once on all the div then

$(“div”).one(“click”,function() { ($(this).css(“background-color”, “blue”); });
8) unbind() :- it will just do upposit the bind unbind all the event for match element.

9) blur() :-

trigger blur event on each matched element. Or in other word we can say when focus is lost from the element then this event run.

Ex:- $(“txtName”).blur(function() { $(this).css(“border”,”2px”);});

9) change():- Change event fire when element’s value has been modified.

Ex:- $(“txtName”).change(function() { alert($(“txtName”).text();});

There are many more events which is as follow click(),

dblClick(),error(),focus(),KeyDown(),KeyPress(), keyUp(),Load(),mouseout(),mouseover(),mouseup(),mousedown(),resize(),Scroll(),



JQuery a unique thing part- II

Hello friends,

Here i am with II part of Jquery which is  effects.

as a web developer we all need that over web application should look best  for that we do lot of stuff like css. animation and pictures. now.

JQuery gives us the  freedom to do more with  our web application to look better and best.

the effects are given by Jquery is simple and easy to use. so here we go

Jquery makes it easy to show effects now we don’t have to write lot of code for some specific animation here are some example.

$(“element”).toggle(function1,function2) :- By the name its clear that it will toggle the event which we can use in showing different effects.

Ex- if we want to do colour change of div on different click then we do following code

$(“#divtest”).toggle(function() { $(“divtest”).css(“background-color”, “red”);}, function (“divtest”).css(“background-color”,”blue”);});

in the simillar manner we can do different thing also.

$(“element”).hover(function):- for hover effect.

$(“element”).FadeIn(intAmount) :- for fade in effect.

$(“element”).FadeOut(intAmount):- for fade out effect.

$(“element”).hide(intAmount) :- for hide effect.

$(“element”).show(intAmount) :- for show effect.

$(“element”).animate() :- for animation effect we have animate function

for example lets see below example $(“#btnFade”).click(function() { $(“#dvTest”).animate({ “left”: “+=50px” }, “slow”); });

It will increase left of div test by 50px with slow speed.

$(“element”).slideToggle() :- it will move up or down according to last action did by element for example.

$(“#btnOpen”).click(function() {

$(“#dvTest”).slideToggle(‘slow’, animate());

function animate() {



The above button click wiill slide up or down with slow speed.

$(“element”).slideUp(speeed) :- it will slide up the element with desire speed.

$(“element”).slideDown(speed) :- it will slide down the element with desire speed.

$(“element”).fadeTo(speed,opacity):- the extra element is opacity means we can define opacity also with speed for particular element fade effect.

$(“element”).Stop() :- it will stop all the animation running on the element.

i will provide the example of all this things in coming up session.



enjoy the JQuery.

AJAX Basic Part -II

Hello friends ,

Here  i am with next topic of AJAX  basic which is part II. so next step is simple example so  here we go with simple example.

As part of AJAX basic I just come with below example in this we create two page one is with server coding & another with client coding.

My main aim here to get result by ajax with out post back so we just try to get current time as result.

For this we write code in default.aspx page as below

<script language =”javascript” type=”text/javascript” >

var myServerRequest;

function callAjax() {

try {

myServerRequest = new XMLHttpRequest();




catch (ex) {

try {

myServerRequest = new ActiveXObject(“Microsoft.XMLHTTP”);


catch (ax) {

try {

myServerRequest = new ActiveXObject(“Msxml2.XMLHTTP”);


catch (ax1) {

return false;





function Callserver() {


if (myServerRequest != null) {‘GET’, “serverCode.aspx”, true);

myServerRequest.onreadystatechange = myServerResponse;



return false;


function myServerResponse() {

if (myServerRequest.readyState == 4) {

if (myServerRequest.status == 200) {

document.getElementById(‘dvResult’).innerHTML = myServerRequest.responseText;

} else {

document.getElementById(‘dvResult’).innerHTML = ‘Oops Error’;



return false;




Here we have 3 main function

1. CallAjax :- it is responsible for Assigning XMLHttpRequest Object.

2. myserverResponse :- by the name it is clear that it use for holding the result what ever pass by server.

3. callServer :- This function is call on any event on button and it sum up the above 2 events.

On server Page at page load we do following code

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load



End Sub

Here we just write time as response then we end response.

If you do not do response.end() then html of server page also comes.

you can download the code from


just copy and paste code in your page and it will work.



AJAX Basic Part -I

Dear all ,

Today i am starting basic of AJAX . so please bear with me if you find any thing missing let me know as far as my concern i will cover basic information which is require a programmer to know and how it will work.

1. What is Ajax ?

Answer: Ajax Stands for Asynchronous JavaScript And XML. It’s a way to make web application like windows application, give use rich Interface.


2. How it Works ?

By working as a extra layer between user browser and server it handle server communication in background submit server request take response from server, the response data integrated in page seamlessly without post back of page. This layer often refers as AJAX engine or AJAx framework.

When ever you click on link or submit form by pressing button then you make a http request. So the page is post back.

XMLHttpRequest is object that can be handle with JavaScript and we can achive goal to take http request without postback.

When we using AJAX layer then we do asynchronous post back which means request to server made in background

The flow is as follows

Web page Request –> Make xml Http Request object –>

Send rquest to server –>

Monitor the request Status –>

Ready state Status –>

respond to client –>

get response–>

Process Return data

For any AJAX work you need to create a object of XMLHttpRequest for many browser you can create objects as follows

var request = new XMLHTTPRequest();

To achive same result in microsoft browser you have to do following thing

var request = new ActiveXObject(“Microsoft.XMLHTTP”);

But some different version use below definition

Var request = new ActiveXObject(“Msxml2.XMLHTTP”);

Or you can write as below

<script language =”JavaScript” type=”text/script”>

var request ;

function defineRequest(){

try {

request = new XMLHTTPRequest();


catch ( ex) {


request = new ActiveXObject(“Microsoft.XMLHTTP”);


catch (ex1){


request = new ActiveXObject(“Msxml2.XMLHTTP”);








XMLHttpRequest object will have following property :

1) onreadystatechange :- Determine which event handler will called when object ready state property changed

2) readyState :- there are following values for this

0 – un initialize

1 – loading

2 – loaded

3 – intractive

4 – completed

3)responseText :- Data return by Server in text format

4) responseXML :- Data return by server in XML format

5) status : – Http Status code

6) statusText :- Http Status Text

And it has following methods

Abort() :- Stop the current Request.

getAllResponseHeaders() :- Return all headers as string

getResponseHeader(x) :- get the x header value in string

Open(‘Method’,url, a) :- specify the Method post /get

url for request

a= true/false determine whether the request handle asynchronously or not.

Send(content) : send a request ( default post data method)



Rest will be in part 2  enjoy coding…


JQuery a unique thing part- I

Dear all,

from today onward’s i am giving some breif introduction of JQuery how it use, how to work with it. and after the whole session i will provide you best example of whole then Jquery stuff.

so starting from point to point


1. What is Jquery ?
Answer: Jquery is JavaScript Library whose main moto is to simplifiy the use of java script for a html document.
It is a light weight JavaScript Library that emphasis intraction between JavaScript & Html.
It simplify  traversing ,event handling , animation and  ajax.

2. How it Works ?
Answer: To Work with Jquery you have to copy the Jquery Js file in your project.
And refrence in your  page like  <script type=”text/javascript” src=”jquery.js”></script>
And you can use it. Second  point is that  you have to start Jquery in  $(document).ready event
And all the event will comes under this ready event.

3. Necessary component to work with + Jquery?

Answer: For Jquery in you need to have to copy two files in your Project and refrence in your project jquery-1.2.6-vsdoc.js & Jquery1.2.6.js

4. Traversing


1) you can find particular element in below type

$(“#elementId) — Suppose there a div box with id dvTest <div id=”dvTest”> then we have to use $(“#dvTest”)

$(“element”), — Suppose there div box in page then if we want to change all the div box background color then we can find all the div with $(“div”)

$(“element”).eq(index) — Now if we want to change the background of of first div only then $(“div”).eq(1) here eq(1) change the background color of index 1 div

$(“element”).find() — Search all the element that match with particular expression like $(“div”).find(“p”) here we find all the p which are in div tag

$(“element”).contnent()- it work same as find

$(“element”).next() – will find next sibling after element.

$(“element”).nextAll() – wiil find all next sibling after element but not there child element.

$(“element”).length() – determine number of element in document
$(“element”).parent.get(0)- will return the parent of element….

$(“element”).prev ;- get the privious sibling of each of element…


you can download Jquery files from its free.

and  you will find tutorial also over there.

i will back soon with my second part of JQuery.



Page Navigation in silverlight

Dear all,

When you are new guy in silverlight then you will find the problem  how to navigate in silverlight page.

even i am also get stucked in that for this reason i am writing this post to help people like me.

As you see the initial this how the default page set or load in silverlight application then you will answer in App.xaml file and you will find below code.

  Private Sub Application_Startup(ByVal o As Object, ByVal e As StartupEventArgs) Handles Me.Startup
        Me.RootVisual = new Page()
    End Sub

 It means that when ever application start  it shows page.xaml  because you have assign RootVisual  Page class object.

now what if you want to navigate from a button click to  other page like rajat.xaml.

for this you have to right some simple code. like below

first in App.xaml Start up event

Private Sub Application_Startup(ByVal o As Object, ByVal e As StartupEventArgs) Handles Me.Startup
        Dim tGrid As New Grid()
        tGrid.Children.Add(New Page())
        Me.RootVisual = tGrid
End Sub

 Then On the button click event of Page.xaml you have to write below code

 Private Sub btnNavigate_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Dim tmp = CType(Application.Current.RootVisual, Grid)
        tmp.Children.Insert(0, New Rajat()) ‘Assign Rajat.xaml page class object to grid child
        tmp.Children.RemoveAt(1) ‘ Remove old page which is page.xaml
        Application.Current.RootVisual = tmp ‘Assign Root visual again the page which we need to show

    End Sub

I hope it will be useful .