Wednesday, September 30, 2009

Page Life Cycle Events

Mainly four type of life cycle in c#
1)page load
2)page init
3)page pre render
4)page unload


Page_Init

The server controls are loaded and initialized from the Web form's view state. This is the first step in a Web form's life cycle.
Page_Load
The server controls are loaded in the page object. View state information is available at this point, so this is where you put code to change control settings or display text on the page.
Page_PreRender
The application is about to render the page object.
Page_Unload
The page is unloaded from memory.
Page_Disposed
The page object is released from memory. This is the last event in the life of a page object.
Page_Error
An unhandled exception occurs.
Page_AbortTransaction
A transaction is aborted.
Page_CommitTransaction
A transaction is accepted.
Page_DataBinding
A server control on the page binds to a data source.
Process Request Method finally renders HTML Page

LINQ

Disadvantages of LINQ over Stored Procedures

  1. Network traffic: SP's need only serialize SP-name and argument data over the wire while LINQ sends the entire query. This can get really bad if the queries are very complex. However, LINQ's abstraction allows Microsoft to improve this over time.

  2. Less flexible: SP's can take full advantage of a database's featureset. LINQ tends to be more generic in it's support. This is common in any kind of language abstraction (e.g. C# vs assembler).

  3. Recompiling:If you need to make changes to the way you do data access, you need to recompile, version, and redeploy your assembly. SP's can sometimes allow a DBA to tune the data access routine without a need to redeploy anything.
Advantages of LINQ over Stored Procedures

  1. Type safety:

  2. Abstraction: This is especially true with LINQ-to-Entities. This abstraction also allows the framework to add additional improvements that you can easily take advantage of. PLINQ is an example of adding multi-threading support to LINQ. Code changes are minimal to add this support. It would be MUCH harder to do this data access code that simply calls sprocs.

  3. Debugging support: I can use any .NET debugger to debug the queries. With SP's, you cannot easily debug the SQL and that experience is largely tied to your database vendor (MS SQL Server provides a query analyzer, but often that isn't enough).

  4. Vendor agnostic: LINQ works with lots of databases and the number of supported databases will only increase. SP's are not always portable between databases, either because of varying syntax or feature support (if the database supports SP's at all).

  5. Deployment: Others have mentioned this already, but it's easier to deploy a single assembly than to deploy a set of SP's. This also ties in with #4.

  6. Easier: You don't have to learn T-SQL to do data access, nor do you have to learn the data access API (e.g. ADO.NET) necessary for calling the SP's. This is related to #3 and #4.

Tuesday, September 29, 2009

Difference between ADO.net Dataset and ADO Recordset


Dataset:

1.With dataset you can retreive data from two different databases and merge them into one dataset.

2.All representations is done in xml.

3.Dataset can be transmitted on HTTP.

Recordset:

1.With recordset you cannot retreive data from two different databases and merge them into one recordset.

2.All representations is done using COM.

3.Recordset cannot be transmitted on HTTP

Monday, September 21, 2009

The out and ref Paramerter in C#

The out and the ref parameters are used to return values in the same variables, that you pass an an argument of a method. These both parameters are very useful when your method needs to return more than one values.

In this article, I will explain how do you use these parameters in your C# applications.

The out Parameter

The out parameter can be used to return the values in the same variable passed as a parameter of the method. Any changes made to the parameter will be reflected in the variable.

public class mathClass
{
public static int TestOut(out int iVal1, out int iVal2)
{
iVal1 = 10;
iVal2 = 20;
return 0;
}
public static void Main()
{
int i, j; // variable need not be initialized
Console.WriteLine(TestOut(out i, out j));
Console.WriteLine(i);
Console.WriteLine(j);
}
}

The ref parameter

The ref keyword on a method parameter causes a method to refer to the same variable that was passed as an input parameter for the same method. If you do any changes to the variable, they will be reflected in the variable.

You can even use ref for more than one method parameters.

namespace TestRefP
{
using System;
public class myClass
{
public static void RefTest(ref int iVal1 )
{
iVal1 += 2;
}
public static void Main()
{
int i; // variable need to be initialized
i = 3;
RefTest(
ref i );
Console.WriteLine(i);
}
}
}

Sunday, September 20, 2009

Joins In Sql Server

Table


Query
Inner Join

select * from car as a inner join
Dept as b On a.CarId=b.id

Outer Join -Full

select * from Emp as a full outer join
Dept as b On a.Id=b.id

Left
select * from Emp as a left outer join
Dept as b On a.Id=b.id

Right
select * from Emp as a right outer join
Dept as b On a.Id=b.id

Result

Wednesday, September 9, 2009

Interview question

How to Insert Values into an Identity Column in SQL Server?
SET IDENTITY_INSERT IdentityTable ON

INSERT IdentityTable(TheIdentity, TheValue)
VALUES (3, 'First Row')

SET IDENTITY_INSERT IdentityTable OFF


How to clone table structure to another table?

1. select top 1 into [NewTable] from [ExistingTable] where ....
or
2. select top 0 into [NewTable] from [ExistingTable]
insert [NewTable] select * from [ExistingTable] where ...

What is Webparts?

Write a syntax for the Uesr Defined Function And Stored Procedure[Delete the data from some Table.]?

What is WebGarden & WebForm?

How to Maintain the CheckBox State in the GridView Paging?

What is Static Constructor?

Interface Vs Abstract ?

Sealed Class?

Serialized Class?

State Management?

Syntax for RAISERROR in Sql Server.?