Saturday, January 19, 2013


Difference between AFTER and INSTEAD OF TRIGGERS


1. Views cannot have AFTER triggers.
2. We can have multiple AFTER triggers on EACH of the Update/Insert/Delete statements, where as we can have only ONE INSTEAD OF triggers for all these.
3. AFTER triggers do not affect the DML operation that caused them, however INSTEAD OF triggers are invoked instead of the DML operation.

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

Comparing features of LangGraph vs CrewAI

LangGraph Orchestration vs CrewAI Orchestration The following table compares LangGraph and CrewAI orchestration across their menta...