Monday, December 21, 2009

Find the Nth maximum salary in sql

Find N th maximum salary using rank() function

select * from(
select dense_rank() over(order by salary desc) as rank,name from employee ) as empsalary
where rank=2

Sunday, December 20, 2009

WCF Binding

There are multiple aspects of communication with any given service, and there are many possible communication patterns: messages can be synchronous request/reply or asynchronous fire-and-forget; messages can be bidirectional; messages can be delivered immediately or queued; and the queues can be durable or volatile. There are many possible transport protocols for the messages, such as HTTP (or HTTPS), TCP, P2P (peer network), IPC (named pipes), or MSMQ. There are a few possible message encoding options: you can chose plain text to enable interoperability, binary encoding to optimize performance, or MTOM (Message Transport Optimization Mechanism) for large payloads. There are a few options for securing messages: you can choose not to secure them at all, to provide transport-level security only, to provide message-level privacy and security, and of course there are numerous ways for authenticating and authorizing the clients. Message delivery might be unreliable or reliable end-to-end across intermediaries and dropped connections, and the messages might be processed in the order they were sent or in the order they were received. Your service might need to interoperate with other services or clients that are only aware of the basic web service protocol, or they may be capable of using the score of WS-* modern protocols such as WS-Security and WS-Atomic Transactions. Your service may need to interoperate with legacy clients over raw MSMQ messages, or you may want to restrict your service to interoperate only with another WCF service or client.
If you start counting all the possible communication and interaction options, the number of permutations is probably in the tens of thousands. Some of those choices may be mutually exclusive, and some may mandate other choices. Clearly, both the client and the service must be aligned on all these options in order to communicate properly. Managing this level of complexity adds no business value to most applications, and yet the productivity and quality implications of making the wrong decisions are severe.
To simplify these choices and make them more manageable, WCF groups together a set of such communication aspects in bindings. A binding is merely a consistent, canned set of choices regarding the transport protocol, message encoding, communication pattern, reliability, security, transaction propagation, and interoperability. Ideally, you would extract all these "plumbing" aspects out of your service code and allow the service to focus solely on the implementation of the business logic. Binding enables you to use the same service logic over drastically different plumbing.
You can use the WCF-provided bindings as is, you can tweak their properties, or you can write your own custom bindings from scratch. The service publishes its choice of binding in its metadata, enabling clients to query for the type and specific properties of the binding because the client must use the exact same binding values as the service. A single service can support multiple bindings on separate addresses.

WCF defines nine standard bindings:

  • Basic binding Offered by the BasicHttpBinding class, this is designed to expose a WCF service as a legacy ASMX web service, so that old clients can work with new services. When used by the client, this binding enables new WCF clients to work with old ASMX services.
  • TCP binding Offered by the NetTcpBinding class, this uses TCP for cross-machine communication on the intranet. It supports a variety of features, including reliability, transactions, and security, and is optimized for WCF-to-WCF communication. As a result, it requires both the client and the service to use WCF.
  • Peer network binding Offered by the NetPeerTcpBinding class, this uses peer networking as a transport. The peer network-enabled client and services all subscribe to the same grid and broadcast messages to it.
  • IPC binding Offered by the NetNamedPipeBinding class, this uses named pipes as a transport for same-machine communication. It is the most secure binding since it cannot accept calls from outside the machine and it supports a variety of features similar to the TCP binding.
  • Web Service (WS) binding Offered by the WSHttpBinding class, this uses HTTP or HTTPS for transport, and is designed to offer a variety of features such as reliability, transactions, and security over the Internet.
  • Federated WS binding Offered by the WSFederationHttpBinding class, this is a specialization of the WS binding, offering support for federated security.
  • Duplex WS binding Offered by the WSDualHttpBinding class, this is similar to the WS binding except it also supports bidirectional communication from the service to the client .
  • MSMQ binding Offered by the NetMsmqBinding class, this uses MSMQ for transport and is designed to offer support for disconnected queued calls.
  • MSMQ integration binding Offered by the MsmqIntegrationBinding class, this converts WCF messages to and from MSMQ messages, and is designed to interoperate with legacy MSMQ clients.

Thursday, November 19, 2009

Jagged Arrays

    A jagged array is an array whose elements are arrays. The elements of a jagged array can be of different dimensions and sizes. A jagged array is sometimes called an "array of arrays." The following examples show how to declare, initialize, and access jagged arrays.

A jagged array is an array of arrays, and therefore its elements are reference types and are initialized to null.
int[][] jaggedArray = new int[3][];
Before you can use jaggedArray, its elements must be initialized. You can initialize the elements like this:
jaggedArray[0] = new int[5];
jaggedArray[1] = new int[4];
jaggedArray[2] = new int[2];

MSDN Link:http://msdn.microsoft.com/en-us/library/2s05feca.aspx

Wednesday, November 18, 2009

Propeties C#

Using Properties (C# Programming Guide)
Properties combine aspects of both fields and methods. To the user of an object, a property appears to be a field, accessing the property requires exactly the same syntax. To the implementer of a class, a property is one or two code blocks, representing a get accessor and/or a set accessor. The code block for the get accessor is executed when the property is read; the code block for the set accessor is executed when the property is assigned a new value. A property without a set accessor is considered read-only. A property without a get accessor is considered write-only. A property with both accessors is read-write.

Unlike fields, properties are not classified as variables. Therefore, it is not possible to pass a property as a ref (C# Reference) or out (C# Reference) parameter.

Properties have many uses: they can validate data before allowing a change; they can transparently expose data on a class where that data is actually retrieved from some other source, such as a database; they can take an action when data is changed, such as raising an event, or changing the value of other fields.

Properties are declared within the class block by specifying the access level of the field, followed by the type of the property, followed by the name of the property, then a code block declaring a get-accessor and/or a set accessor.

MSDN Link
http://msdn.microsoft.com/en-us/library/w86s7x04(VS.80).aspx

Tuesday, November 17, 2009

WCF Architecture

MSDN Link

http://msdn.microsoft.com/en-us/library/ms733128(classic).aspx

Wednesday, November 4, 2009

Update windows form from child to parent

we are opening child forms and doing some calculation.after finished the calculation in child form. whatever changes we made it should be reflected immediately in the main form.for that I am used event handler to update the main form.

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
//Wired Up Here
frm2.RefreshMain += new EventHandler(frm2_RefreshMain);
frm2.ShowDialog();
}
void frm2_RefreshMain(object sender, EventArgs e)
{
//Write your logic here to update datagridview
}

private DataSet CreateDataSet()
{
DataTable table = new DataTable("childTable");
DataColumn column;
DataRow row;
DataSet dataset = new DataSet();
// Create first column and add to the DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "CustID";
column.AutoIncrement = true;
column.Caption = "ID";
column.ReadOnly = true;
column.Unique = true;
// Add the column to the DataColumnCollection.
table.Columns.Add(column);
//// Create second column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "CustName";
column.AutoIncrement = false;
column.Caption = "Name";
column.ReadOnly = false;
column.Unique = false;
table.Columns.Add(column);
dataset.Tables.Add(table);
for (int i = 0; i <= 100; i++)
{
row = table.NewRow();
row["CustID"] = i;
row["CustName"] = "Item " + i;
table.Rows.Add(row);
}
return dataset;
}
DataSet dsCust;
private void BindData()
{
dsCust = CreateDataSet();
dataGridView1.DataSource = dsCust.Tables[0];
}

private void Form1_Load(object sender, EventArgs e)
{
BindData();
}

}

//Code For Form 2

public partial class Form2 : Form{

//Declare event handler here
public event EventHandler RefreshMain;
public Form2()
{
InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)
{

}

protected void UpdateMain()
{
if (RefreshMain != null)
RefreshMain(this, EventArgs.Empty);
}

private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
UpdateMain();
}

}

Friday, October 30, 2009

How To DataGridview To Dataset Code Sample.

      We need to create the datacolumn from the datagridview column.Add created Column in to datatable .Add the datatable in to dataset.loop through the datagridview add data to datatable .

DataTable table = new DataTable("mytable");

DataColumn column;

DataRow row;

DataSet dataset = new DataSet();

column = new DataColumn();

column.DataType = dataGridView1.Columns[0].ValueType;

column.ColumnName = dataGridView1.Columns[0].Name;

table.Columns.Add(column);

column = new DataColumn();

column.DataType = dataGridView1.Columns[1].ValueType;

column.ColumnName = dataGridView1.Columns[1].Name;

table.Columns.Add(column);

dataset.Tables.Add(table);

for (int rowCount = 0; rowCount < dataGridView1.Rows.Count - 1; rowCount++)

{

row = table.NewRow();

row[0] =Convert.ToInt32(dataGridView1.Rows[rowCount].Cells[0].Value);

row[1] = dataGridView1.Rows[rowCount].Cells[1].Value.ToString();

table.Rows.Add(row);

}

return dataset;