Wednesday, August 17, 2011

IDENT_CURRENT–Retrieve last inserted identity of record

SELECT IDENT_CURRENT(‘<tablename>’)


It returns the last IDENTITY value produced in a table, regardless of the connection that created the value, and regardless of the scope of the statement that produced the value.
IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope.

Happy Coding…

Tuesday, June 7, 2011

Simulating ListView’s ItemCommand Event

Data controls in asp.net like GridView, DataList, Repeater, ListView,… are having an event called ItemCommand.

This event will raise whenever any button, linkbutton,… are clicked.

But my requirement is to call the ItemCommand event whenever the ListView.Databind() is done.

Below is the procedure I followed for that.

System.Web.UI.WebControls.LinkButton lnkbtn = (System.Web.UI.WebControls.LinkButton)lvMyAlbums.Items[0].FindControl("lnkAlbum");

            ListViewCommandEventArgs ev = new ListViewCommandEventArgs(lvMyAlbums.Items[0], lnkbtn, new CommandEventArgs(lnkbtn.CommandName, lnkbtn.CommandArgument));

            // Call ItemCommand handler

            lvMyAlbums_OnItemCommand(lvMyAlbums, ev);

 

Happy coding…

Wednesday, June 1, 2011

Convert DateTime to Indian Standard Time format in SQL Server

DATEADD() function would be used to convert UTC to IST in SQL Server.

Below is the sample code for that.

DECLARE @UTCTime As DATETIME;
SET @UTCTime = GETUTCDATE();
SELECT DATEADD(MI, 330, @UTCTime) AS IST

Happy Coding…