Sunday, November 13, 2011

The confusing "Invalid postback or callback argument" error in an .aspx page.


Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.




Here is one possible condition, in which I could simulate this error :

You populate a GridView in Page_Load always. Instead normally you should do it only in case of post bacK :

       if ( !Page.IsPostBack)
{
            //.... code to populate the gridview
            pui.PopulateGrid(CustomerGridView, scmbl_cust.GetCustomerDataTable());
 
}

If you comment the !Page.IsPostBack, you will get the above error.

Thursday, September 15, 2011

GridView Vertical text in headers

http://forums.asp.net/t/1049758.aspx/1




.verticaltext

{

font:bold 10px Tahoma;

color: #0000FF;

writing-mode: tb-rl;

filter: flipH() flipV();

}

So what I am doing is loading my gridview like usual, and then adding a _DataBound event for the gridview.  So here is the code to rotate the header row.

Protected Sub gvMatrix_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvMatrix.DataBound

Dim style As New Web.UI.WebControls.Style

Dim row As GridViewRow = gvMatrix.HeaderRow

style.CssClass = "verticaltext"

For Each cell As TableCell In row.Cells

cell.ApplyStyle(style)

Next

end sub

Friday, September 2, 2011

Paging at DAL




PAGING AT DAL

1. http://www.codeproject.com/KB/webforms/GridViewCustomPaging.aspx
====================================================================
CREATE PROCEDURE [usp_GetProducts]
@startRowIndex int,
@maximumRows int,
@totalRows int OUTPUT

AS

DECLARE @first_id int, @startRow int

SET @startRowIndex =  (@startRowIndex - 1)  * @maximumRows

IF @startRowIndex = 0
SET @startRowIndex = 1

SET ROWCOUNT @startRowIndex

SELECT @first_id = ProductID FROM Products ORDER BY ProductID

PRINT @first_id

SET ROWCOUNT @maximumRows

SELECT ProductID, ProductName FROM Products WHERE
ProductID >= @first_id
ORDER BY ProductID

SET ROWCOUNT 0

-- GEt the total rows

SELECT @totalRows = COUNT(ProductID) FROM Products
GO
====================================================================

2. http://www.aspsnippets.com/Articles/Custom-Paging-in-ASP.Net-GridView-using-SQL-Server-Stored-Procedure.aspx

====================================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
CREATE PROCEDURE GetCustomersPageWise
      @PageIndex INT = 1
      ,@PageSize INT = 10
      ,@RecordCount INT OUTPUT
AS
BEGIN
      SET NOCOUNT ON;
      SELECT ROW_NUMBER() OVER
      (
            ORDER BY [CustomerID] ASC
      )AS RowNumber
      ,[CustomerID]
      ,[CompanyName]
      ,[ContactName]
     INTO #Results
      FROM [Customers]
     
      SELECT @RecordCount = COUNT(*)
      FROM #Results
           
      SELECT * FROM #Results
      WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
     
      DROP TABLE #Results
END
GO
====================================================================

Saturday, August 27, 2011

Difference between abstract classes and interfaces

What is the difference between an interface and an abstract class ?

Interface

Abstract Class

Interfaces are implemented  i.e.
instances of interfaces cannot be created by derived classes.

Classes are inherited   i.e.
derived classes do create instances of abstract classes

You cannot use access specifiers with members of an interface. All interface
members are implicitly public and cannot have any other access specifier.

Members of abstract class can have all access specifiers except private i.e.
they can be internal, public, protected and protected internal but not private.

All the members of an interface are implicitly abstract (although you cannot
explicitly use abstract keyword because it not allowed to use access specifiers
in interface).

An abstract class can have non-abstract members.

Interface cannot have static members.

Abstract classes can have non-abstract static members.

A class can inherit one or more interfaces.

A class can inherit from only one abstract (or non-abstract ) class.

Modifying an interface results in breaking the existing clients. This is because
clients must implement all interface members, and interface members are only
declarations , no code or values are allowed.

Not all modifications in an abstract class break existing clients. E.g. adding a
new non-abstract method to the base abstract class will not break existing
clients.

Interfaces CANNOT have constructors and destructors.

Constructors and destructors ARE ALLOWED in abstract classes.
The abstract class constructors cannot be abstract or private.

When will an abstract class become equivalent to an interface ?
To equivalent to an interface , the abstract class must meet following conditions :
•    All of its members must be abstract.
•    It should not have members other than methods,properties,events and indexers.
•    Access modifiers to all of its members must be public.


Tuesday, August 23, 2011

On DbCommand, ExecuteReader, ExecuteScalar, etc and creating database through ADO.NET

Ideally we run a DML query in ExecuteNonQuery.
What will happen when a DML query is run in ExecuteReader,ExecuteScalar,or ExecuteXmlReader  ?


ExecuteReader
No Exception is thrown, RecordsAffected contains the number of records affected.
HasRows returns false, .Read returns false, RecordsAffected contains number of records afftected.
When read is attempted, error "Invalid attempt to read when no data is present" is thrown

ExecuteScalar
No Exception is thrown, query is executed, however NULL object is returned,
Returns the first column of first row, is not found returns null ( null object).
When the return value is actually null, DBNull.Value is returned.

ExecuteXmlReader
InvalidOperationException is thrown , however, query is executed before throwing an exception.
        "Invalid command sent to ExecuteXmlReader.  The command must return an Xml result."   

Another interesting question :
Can you create database and other objects using the DbCommand objects?
YES.
But you cannot immediaately switch to the database because you cannot use GO statements in
DbCommand command texts, so you need to change the connection string to change 'Initial Catalog' name
and then issue rest of commands.

What are the attributes of connection string ?

Data Source : Name/IP of the server
Initial Catalog : Name of the database
User ID  : User id
Password : user password
Persist Secutiry Info : True by default.

Wednesday, July 20, 2011

Can you use JOIN in UPDATE ?

YES.

e.g.
update
set
from
where

Remember the syntax :
UPDATE TableA
SET colname=TableB.colname ( or anything else)
FROM TableA, TableB
WHERE  <join condition>


Have a look at following links for more information :
SUMMARTIMELISTSENSUMMER2011.id >= #tempRSC.id and SUMMARTIMELISTSENSUMMER2011.id <= #tempRSC.laststoprowid
SUMMARTIMELISTSENSUMMER2011 ,#tempRSC
routename = #tempRSC.f33
SUMMARTIMELISTSENSUMMER2011

Friday, July 15, 2011

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public
{

{

Label1.Text = abcd1.ret().ToString();



Label1.Text +=
}
}
partial class _Default : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e)abcd abcd1 = new abcd(30);ZZZZ z = new ZZZZ();aa a = new ZZZZ();bb b = new ZZZZ();" " + z.meth() + " " + a.meth().ToString() + " " + b.meth();class ZZZZ : aa, bb{

{

}
public int meth()return 55;#region

{

}
aa Membersint aa.meth()return 66;#endregion
#region

{

}
bb Membersint bb.meth()return 77;#endregion}interface aa{

}
int meth();interface bb{

}
int meth();struct abcd{


{
x =
}
public aaaaaa x;public abcd(int z)new aaaaaa();public class aaaaaa{


{
a = 10;
}
}

{

}
}
public int a;public aaaaaa()public int ret()return x.a;

OOP fundamentals : Explicite Interface Implementation and Structures can contain class

%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%20using%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20System%3B%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Eusing%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20System.Collections.Generic%3B%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Eusing%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20System.Linq%3B%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Eusing%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20System.Web%3B%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Eusing%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20System.Web.UI%3B%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Eusing%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20System.Web.UI.WebControls%3B%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Epublic%0D%0A%7B%0D%0A%0D%0A%7B%0D%0A%0D%0ALabel1.Text%20%3D%20abcd1.ret().ToString()%3B%0D%0A%0D%0A%0D%0A%0D%0ALabel1.Text%20%2B%3D%20%0D%0A%7D%0D%0A%7D%0D%0A%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Epartial%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Eclass%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E_Default%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3A%20System.Web.UI.%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3EPage%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Eprotected%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Evoid%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20Page_Load(%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Eobject%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20sender%2C%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3EEventArgs%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20e)%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3Eabcd%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20abcd1%20%3D%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Enew%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3Eabcd%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E(30)%3B%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3EZZZZ%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20z%20%3D%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Enew%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3EZZZZ%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E()%3B%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3Eaa%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20a%20%3D%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Enew%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3EZZZZ%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E()%3B%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3Ebb%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20b%20%3D%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Enew%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3EZZZZ%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E()%3B%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%23a31515%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%23a31515%3B%20font-size%3A%20x-small%3B%22%3E%22%20%22%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%2B%20z.meth()%20%2B%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%23a31515%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%23a31515%3B%20font-size%3A%20x-small%3B%22%3E%22%20%22%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%2B%20a.meth().ToString()%20%2B%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%23a31515%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%23a31515%3B%20font-size%3A%20x-small%3B%22%3E%22%20%22%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%2B%20b.meth()%3B%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Eclass%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3EZZZZ%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3A%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3Eaa%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%2C%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3Ebb%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%7B%0D%0A%0D%0A%7B%0D%0A%0D%0A%7D%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Epublic%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Eint%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20meth()%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Ereturn%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%2055%3B%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%23region%0D%0A%0D%0A%7B%0D%0A%0D%0A%7D%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20aa%20Members%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Eint%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3Eaa%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E.meth()%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Ereturn%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%2066%3B%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%23endregion%0D%0A%23region%0D%0A%0D%0A%7B%0D%0A%0D%0A%7D%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20bb%20Members%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Eint%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3Aize%3A%20x-small%3B%22%3Ebb%3C%2Fspan%3E^ 2/?+{tyle%3D%22font-size%3A%20x-small%3B%22%3'8- W"aH7[pspan%20style%3D%22color%3A%20blue%3B%20fp
po_F= ~n c %22%3E%3Cspan%20style%3D%22color%3A%20bl,@ mr1[k Dq|N-small%3B%22%3Ereturn%3C%2Fspan%3E%3C%2F@J K + ) E D%22font-size%3A%20x-small%3B%22%3E%2077"< $# /$ ,5:node%3B%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%23endregion%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%7D%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Einterface%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3Eaa%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%7B%0D%0A%0D%0A%7D%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Eint%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20meth()%3B%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Einterface%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3Ebb%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%7B%0D%0A%0D%0A%7D%0D%0A%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Eint%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20meth()%3B%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Estruct%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3Eabcd%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%7B%0D%0A%0D%0A%0D%0A%7B%0D%0Ax%20%3D%20%0D%0A%7D%0D%0A%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Epublic%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3Eaaaaaa%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20x%3B%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Epublic%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20abcd(%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Eint%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20z)%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Enew%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3Eaaaaaa%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E()%3B%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Epublic%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Eclass%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20%232b91af%3B%20font-size%3A%20x-small%3B%22%3Eaaaaaa%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%7B%0D%0A%0D%0A%0D%0A%7B%0D%0Aa%20%3D%2010%3B%0D%0A%7D%0D%0A%7D%0D%0A%0D%0A%7B%0D%0A%0D%0A%7D%0D%0A%7D%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Epublic%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Eint%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20a%3B%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Epublic%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20aaaaaa()%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Epublic%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Eint%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20ret()%3C%2Fspan%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3E%3Cspan%20style%3D%22color%3A%20blue%3B%20font-size%3A%20x-small%3B%22%3Ereturn%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan%20style%3D%22font-size%3A%20x-small%3B%22%3E%20x.a%3B%3C%2Fspan%3E

OOP fundamentals : Explicite Interface Implementation and Structures can contain class

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public
{

{

Label1.Text = abcd1.ret().ToString();



Label1.Text +=
}
}
partial class _Default : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e)abcd abcd1 = new abcd(30);ZZZZ z = new ZZZZ();aa a = new ZZZZ();bb b = new ZZZZ();" " + z.meth() + " " + a.meth().ToString() + " " + b.meth();class ZZZZ : aa, bb{

{

}
public int meth()return 55;#region

{

}
aa Membersint aa.meth()return 66;#endregion
#region

{

}
bb Membersint bb.meth()return 77;#endregion}interface aa{

}
int meth();interface bb{

}
int meth();struct abcd{


{
x =
}
public aaaaaa x;public abcd(int z)new aaaaaa();public class aaaaaa{


{
a = 10;
}
}

{

}
}
public int a;public aaaaaa()public int ret()return x.a;

Monday, July 11, 2011

SQL Server Date Time : What will be the output of cast(0 as datetime) ?

SQL DATE TIME
1. What will be the output of following ?
select CAST (0 as datetime)
'1900-01-01 00:00:00.000'
returns epoch
2. How to create a date from given integers for year , month,date
Declare @DayOfMonth TinyInt
Set @DayOfMonth = 20
Declare @Month TinyInt
Set @Month = 6
Declare @Year Integer
Set @Year = 2006
Select DateAdd(day, @DayOfMonth - 1,DateAdd(month, @Month - 1,DateAdd(Year, @Year-1900, 0)))
3. How to get first date of current month ?
select convert(datetime ,
cast(DATEPART(year , getdate()) as nvarchar(10)) + '-' +
cast (DATEPART(month , getdate()) as nvarchar(5)) +
'-01'
)

Friday, July 8, 2011

static

1. Which operators cannot be overloaded  ?
 =, ., ?:, ->, new, is, sizeof, typeof
2. Comparsion operator
 ==, !=, <, >, <=, >=
They must be overloaded in pairs.
3.  How do you overload operators ?
By defining static member functions using the operator keyword.
4. Can non-static classes contain static members ?
 YES.
5. Can static classes contain non-static members ?
 NO.
6. Can you access static members of non-static classes using instances of non-static members ?
 NO. Static members must be accessed using thier class names, not using instances
7. What all can be static ?
method, field, property, or event
constructors can be static.
const behave like static fields , but static keyword cannot be used with them
operator overloading functions are always a static
Indexers cannot be static, the allowed access specifiers for indexers are only 

Wednesday, July 6, 2011

It is mutually exclusive to mark a method with the new and override keywords.

Classes , Structs and Interfaces

Classes
What can be the members of class, struct and interfaces?
Class: (http://msdn.microsoft.com/en-us/library/0b0thckt.aspx)
·         Constructors
·         Destructors
·         Constants
·         Fields
·         Methods
·         Properties
·         Indexers
·         Operators
·         Events
·         Delegates
·         Classes
·         Interfaces
·         Structs

Struct: (http://msdn.microsoft.com/en-us/library/ah19swz4.aspx)

Interfaces :  methods, properties, events, indexers  (http://msdn.microsoft.com/en-us/library/ms173156.aspx)


Class
Struct
Interface
Constructors
Y
Y
N
Destructors
Y
N
N
Constants
Y
Y
N
Fields
Y
Y
N
Methods
Y
Y
Y
Properties
Y
Y
Y
Indexers
Y
Y
Y
Operators
Y
Y
N
Events
Y
Y
Y
Can a static class contain non-static members?
NO. (http://msdn.microsoft.com/en-us/library/79b3xss3(v=vs.80).aspx).
The main features of a static class are:
·         They only contain static members.
·         They cannot be instantiated.
·         They are sealed.
·         They cannot contain Instance Constructors.
Constructors:
- Constructors cannot be “virtual”.
- They cannot be inherited.
- Constructors are called in the order of inheritance.
- Constructors can be overloaded.
- special function that is called when class is instantiated.
- same name as the class.
- does not have a return type.
- used to initialize values.
- can have parameters.
- compiler will supply one if not declared.
Can you define constructors for struct?
We cannot define default constructor for structs, because one is compulsorily provided by compiler.
However, we can define constructors for structs that take parameters.

Remember that the default constructor is called when we use new with struct. However, objects based on structs can be initialized or assigned and then used.
e.g. int I = new int();  //valid ; can be used
int i ; I = 33; //valid ; can be used
int I; // cannot be directly used without assigning a value, because new is not given, hence value is not initialized.
Can you define a default constructor for a strut ?
NO. It is compulsorily provided by compiler.
In how many type value types can be created? 
By calling new : int I = new int();
By assigning a value: int I = 44; //using new is not a requirement.
A base class has no default constructor but has some parametered constructors. Will the derived class have to do something?
If a base class does not offer a default constructor, the derived class must make an explicit call to a base constructor by using base. (MSDN http://msdn.microsoft.com/en-us/library/ms173115.aspx#Y1200)
Can constructors be inherited? NO.
What is the order of calling constructors and destructors in an inheritance chain ?
Constructors : Least derived (base) to Most Derived.
Destructors : Most Derived to Least Derived. (http://msdn.microsoft.com/en-us/library/66x5fx1b(v=vs.80).aspx)
Consider the following :
Class A {
               Public A() {}
              ~A(){}
}
Class B  : A {
               Public B() {}
              ~B(){}
}


What will be the order of ctor/dtor in following cases ?
B b = new A(); //INVALID
A a = new B();  // ctor A, ctor B , dtor B , dtor A
In a nested class, can you access members of container class ?
NOT DIRECTLY, you have to pass an instance of container to nested class either in nested class’s ctor or some other method.
Destructors :
·         Destructors cannot be defined in structs. They are only used with classes.
·         A class can only have one destructor.
·         Destructors cannot be inherited or overloaded.
·         Destructors cannot be called. They are invoked automatically.
·         A destructor does not take modifiers or have parameters.
What are the differences between classes and structs ?
Class
Struct
Classes are reference type
Struct is a  value type
Classes can inherit from another class  or interface but not from a class (struct cannot be a base of a class)
Structs cannot inherit from other structs or classes
A struct cannot inherit from another struct or class, and it cannot be the base of a class
http://msdn.microsoft.com/en-us/library/aa288471(v=vs.71).aspx
Classes can have destructors
Structs cannot have destructors.
Encapsulation
What is the default access level of members in a class?
Private. This is applicable to constructor also, if a constructor is provided and no access specifiers are provided for it.
However, if you do not provide a default constructor to a class, the default parameterless constructor provided by the compiler is public.
Can you inherit from a class which has only  private constructors ?
No. It is not possible to inherit a class that has only a private constructor.
Can you inherit from a static class ?
NO. Static classes are sealed and cannot be inherited. http://msdn.microsoft.com/en-us/library/79b3xss3(v=vs.80).aspx
Can a static class contain not static methods?
Inheritance
What is class inheritance and interface inheritance?

Can you inherit from a class which has only  private constructors ?
No. It is not possible to inherit a class that has only a private constructor.
What is the difference in virtual and abstract methods?
When talking about the base class, a virtual method may or may not contain implementation. But, an abstract method cannot contain implementation.
When talking about the (non-abstract) derived class, a virtual method may or may not be overridden, but an abstract method must be overridden ( or actually implemented).



Polymorphism
How many types of overloading are supported?
Method overloads and operator overloading.
What is operator overloading?

How to check local and global angular versions

 Use the command ng version (or ng v ) to find the version of Angular CLI in the current folder. Run it outside of the Angular project, to f...