Wednesday 27 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:-


ASP.NET: Setting Key Values In Reference Config File

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

ASP.NET: Setting Key Values In Reference Config File
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: Setting Key Values In Reference Config File

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:-

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

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

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

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

kailash chandel
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 .


ASP.NET: Ajax Call To Server Side Function





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".


ASP.NET: Ajax Call To Server Side Function







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:-
ASP.NET: Ajax Call To Server Side Function
After that write the code:
ASP.NET: Ajax Call To Server Side Function
  

Now when we run the program we have the initial screen:

ASP.NET: Ajax Call To Server Side Function

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

ASP.NET: Ajax Call To Server Side Function


The text of the paragraph has been replaced by the message returned by the method  ServerSideMethod.







Thursday 21 February 2013

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:




Query:-



Output:-








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:-



Query:-





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 developer group we have a gap between 2 and 4 . Click for detail on rank().


DENSE_RANK :- 
Returns a rank of each row within the partition of a result set. But in this case there is no gap between the ranks. Let us use the DENSE_RANK  for above case.

Query:- 





Output:-

We can clearly notice in this case the rank continues from the  last rank. It is not affected by the row count.
We have same rank 1 for three records for the group designer but next rank is 2 instead of 4 which we get in case of rank(). Same can be be noticed for the developer group.


Wednesday 20 February 2013

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.
e.g.
We have a table sample For Ranking Functions with the following records.

Sql: Over And Partition By Clause

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:


Sql: Over And Partition By Clause

The output of the above query will be as:

The output of the above query

Sql: Use Of Ranking Function rank()

Kailash ChandelRanking functions are used with the over clause.
Before we continue to work with the ranking functions we must have knowledge of the partition.by

 rank():
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


Use of ranking functions rank()
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:
Use of ranking functions rank()

  • 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 the two records. rank() will rank the rows of  result set and show the record at last according the condition of rank.










How to get code from a published ASP.Net build where we don't have source code?

If you have ever lost or misplaced your source code for an ASP.Net web application, you might wonder if there is a way to recover it from th...