Skip to main content


Showing posts from February, 2013

ASP.NET: Setting Key Values In Reference Config File

We can set the keys values of <appSetting>  in a reference file. The procedure is:

Add a new item i.e. web configuration file from solution explorer name it keys.config(you can name it our own).
write the following code in keys.config:-

In the web.config file set the reference of the keys.config file as follows:-

We are finished with the reference stuff. Now we can access the values for key value1 and value2 in the code file by following code lines:-

ASP.NET:Set Constants In Web.Config File And Access Them In Code File

Sometimes we need to use the constants in different parts of our project.  We can simply use constant values. But what if after a span of time (months or years) the constant value changes?  Then the programmer need to change the constant value on every place where he had used the constant.
 One solution to this problem is to set the value of constant in web.config file in the <appSettings> tag. Then we can access this value at code file wherever we require.Let me explain it with example.
Put the following code inside your web.config file:-

Now to access this values inside the code file write the following code:-

Now wherever you use the value1 and value2 values will be changed whenever you change the value attribute of the key inside <appSettings>   tag of the web.config file. You can place the keys and values in separate file and reference it in web.config file Click Here for code.

ASP.NET: Ajax Call To Server Side Function

To call the server side function we will use the ajax call. For this we need to call the server side function by a ajax call. To explain this we will have an example.
       Let us have a page named ajaxcall.aspx .  We will take a div with id myDiv and put its text  "Before ajax call when server side function is not called." Now place a button with id Button1 .

There is a method named ServerSideMethod defined on ajaxcall.aspx.cs page.  This method returns the text  "After ajax call when server side function is  called".

Now we want to call the  method ServerSideMethod   on the click of button Button1   and change the text of div myDiv to the message returned by ServerSideMethod. To do this we will make the ajax call to the method by following code: Firstly add the reference:- After that write the code:
Now when we run the program we have the initial screen:

And after click on the Check button output will be:-

The text of the paragraph has been replaced by the mess…

Sql: Window Functions(ROW_NUMBER, RANK, DENSE_RANK)

Window functions are the functions which operates on the window(set of  rows). Window refers to the  set of rows obtained as a result of some function.

1.ROW_NUMBER :-The ROW_NUMBER function is used to generate a sequence of numbers based in a set in a specific order, in easy words, it returns the sequence number of each row inside a set in the order that you specify.
Let us have the records in table:



2. Rank:-  rank()  returns a rank of each row within the partition of a result set.The ranking is calculated by 1 plus the number of previous  rows.The function RANK returns the result with a GAP after a tie,Let  us have a  sampleForRankingFunctions table of database emp with following records:-


Output:- After we run the query we will get the output as follows.

As mentioned in the definition in a group it continue to rank from previous row count therefore we get a gap and after 1 rank becomes 4 because there is a gap of three records. for designer group. Similarly for…

Sql: Over And Partition By Clause

Over(): Over() looks over the result set rows of the aggregation functions.Hence OVER() is implemented in the aggregation functions, it allow-us to access the details of the rows that have been aggregated by the aggregate functions.

Partition by: Over and partition by clause is used to wire up the result on the basis of particular field value.
We have a table sample For Ranking Functions with the following records.

Now we want to show the sum of salary by grouping them by salary. We have four records with salary 14 therefore sum is 56 and in second group we have two records with salary 20 hence sum is 40. The query will be:

The output of the above query will be as:

Sql: Use Of Ranking Function rank()

Ranking functions are used with the over clause.
Before we continue to work with the ranking functions we must have knowledge of the

Returns the rank of each row within the partition of a result set.
The syntax for using rank functions is

select * from(select *, rank() over(partition by <fieldname>order by <fieldname> asc) as ranking from table_name)testing where ranking<3

Above query will return two records for each group with the all fields.

To understand the use of rank function let us take the an example:-
                Let us have a table named sampleForRankingFunctions having the following records

Now we want to show first two records of each group then we can write the query as:

The output of the query will be:
rank() returns a rank of each row within the partition of a result set. Another example of the rank use is when you want to show top n records having two records at final position, now question is that which record will be displayed out of …