Tuesday, July 27, 2010

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());
}
}

COLLECTIONS INTERFACE USING QUEUE

Represents a first-in, first-out collection of objects.

Namespace: System.Collections

the .NET Framework provides the serialized Queue class that implements both the ICollection and the IEnumerable interfaces.
To add value in queue , Enqueue method is used.
Peek()-the first item added to a queue stays in front of all others that would be added.
The process of removing an item from a queue is called "dequeue".


Example Programe

using System;
using System.Collections;
class queue1
{
public static void Main(string[] args)
{
Queue q1=new Queue();
q1.Enqueue(55);
q1.Enqueue(65);
q1.Enqueue(75);
q1.Enqueue(85);

Console.WriteLine(q1.Dequeue());
Console.WriteLine(q1.Peek());
Console.WriteLine(q1.Dequeue());
}
}

PROPERTIES IN C#

In the .NET Framework provides a standard way to specify and mutate name in the C# language.
you can access this type and avoid writing your own name routines.Properties combine aspects of both fields and methods
Properties are members that provide a flexible mechanism to read, write, or compute the values of private fields
A get property accessor is used to return the property value, and a set accessor is used to assign a new value. These accessors can have different access levels. For more information, see Accessor Accessibility.


Example Programe

using System;
using System.Collections;
public class Car
{
private string name;
public string Name
{
get{return name;}
set{name=value;}
}
public Car(string n)
{name=n;}
}
public class CarCollection:CollectionBase
{
public void Add(Car newcar)
{List.Add(newcar);}
public void Remove(Car oldcar)
{List.Remove(oldcar);}
public Car this[int index]
{
get{return (Car)List[index];}
set{List[index]=value;}
}
}








class properties
{
public static void Main(string[] args)
{
CarCollection c=new CarCollection();
c.Add(new Car("santro"));
c.Add(new Car("suzuki"));
c.Add(new Car("nano"));
c.Add(new Car("azer"));

foreach(Car car in c)
{
Console.WriteLine(car.Name);
}

Console.WriteLine(c[2].Name);
c[2].Name="zen";
Console.WriteLine(c[2].Name);

foreach(Car car in c)
{
Console.WriteLine(car.Name);
}
}
}