Thursday, August 5, 2010

Build Solution and Rebuild Solution option in VS.Net

We have two options for compiling and creating builds for our application. Such as

1)Build Solution
2)Rebuild Solution

1)Build Solution
The Build Solution option compiles only particular project files and components in the solution that have changed since the last build.
For example: Assume that we have two projects P1 and P2 in our solution WebsiteSolution. When we compile the solution using Build Solution option after making some changes to P1 only Pj1 will be compiled and built but P2 will not be compiled.

2) Rebuild Solution
The Rebuild option builds all project files and components.
For example : Assume that we have two projects P1 and P2 in your solution WebsiteSolution. When you compile the solution using Rebuild Solution option after making some changes to P1, both P1 and P2 will be compiled and built even though there are no changes made to P2.

Tuesday, July 27, 2010

Ranking Functions in SQL server

Let’s add RANK function onto this query, you can see additional column ranking the data.
 For example:
 the  Account Id  of ' kingslin ' are assigned a rank of 1 as they are equal, the Account Id  of Bala are assigned the next rank, stalin the next, etc. This is a simple way of assiging a Account Id   by class or category depending on how we order the data - the rank value of 3 simply means that all data with this rank number is the same.
Here I have used Table name with schema name (Customer.ShippingAddress)
Customer is the schema name for that table.



 select
 RANK() over (order by s_Acc_id) as Rank
, ROW_NUMBER() over (order by s_Acc_id) as RowNumber
, s_Acc_id from Customer.ShippingAddress


1 1    kingslin
 2 2    Bala
 3 3    Rajesh
 4 4    varakulan
 5 5    stalin
5 6    stalin
5 7    stalin
5 8    stalin
 9 9    vasanth
9 10    vasanth

Here Stalin Accound Id has the same values generated by the RANK and ROW_NUMBER functions giving us a very simple way of deduplicating the data.
How its working
•    the 'order by' clauses are used to bring specific sorted list
•    the ROW_NUMBER function gives sequential numbers
•    the RANK function allocates a value to each block of data matching the order criteria

Create CTE table and filter rows

 with AlphaRank(Rank, RowNumber, s_Acc_id) as (
select
  RANK() over (order by s_Acc_id) as Rank
, ROW_NUMBER() over (order by s_Acc_id) as RowNumber
, s_Acc_id
from Customer.ShippingAddress
)
select s_Acc_id from AlphaRank where Rank=RowNumber

output is :

kingslin
Bala
Rajesh
varakulan
stalin
vasanth

ROW_NUMBER function using Sql server

ROW_NUMBER using Sql server

Using Row_number function we can get a listing of table with a sequential list.


select ROW_NUMBER() over (order by s_Acc_id) as RowNumber, s_Acc_id from Customer.ShippingAddress



Output is

1    kingslin
2    Bala
3    Rajesh
4    varakulan
5    stalin
6    stalin
7    stalin
8    stalin
9    vasanth
10    vasanth



Using this Row_number function, we can find out particular row.

Example :

You are running a sql query , you need 2nd row of that result,
Using CTE and Row_number function , we can get particular row

Example Query:


WITH OrderedOrders AS
(select ROW_NUMBER() over (order by s_Acc_id) as RowNumber, s_Acc_id from Customer.ShippingAddress
)
SELECT *
FROM OrderedOrders
WHERE RowNumber=2

Output is
2    Bala

Wednesday, July 21, 2010

Compare date with current date using c#

Here I have publish how to compare text box date with current date using c#

DateTime dat1 = DateTime.Parse(txtFromDate.Text);

DateTime dat2 = DateTime.Parse(DateTime.Now.ToShortDateString());

if (DateTime.Compare(dat1, dat2) > 0)
{
lbl.Text = "Date must be less than current date.";

}

First Date I have got from my application, Second date is system date , using
c# compare method , I have compared both date.

Thursday, July 1, 2010

COLLECTIONS INTERFACE USING STACK

Represents a simple last-in-first-out (LIFO) non-generic collection of objects.

Namespace: System.Collections

First action you need to do on Stack is Push elements into it.
The Pop method on stack, and also the Peek method. When you call Pop, the elements from the top of the Stack is returned, and the element is removed from the collection.
The Pop and Peek methods both act on the top of Stack.


Example Programe

using System;
using System.Collections;
class stack
{
public static void Main(string[] args)
{
Stack s1=new Stack();
s1.Push(10);
s1.Push(20);
s1.Push(30);
s1.Push(40);

Console.WriteLine(s1.Pop());
Console.WriteLine(s1.Peek());
Console.WriteLine(s1.Pop());
}
}