Thursday, January 27, 2011

Get Last Executed Query with Time

Using below query you can easily trace the query that are executed earlier..


Select dmStats.last_execution_time as 'Last Executed Time',dmText.text as 'Executed Query' from sys.dm_exec_query_stats as dmStats Cross apply sys.dm_exec_sql_text(dmStats.sql_handle) as dmText Order By dmStats.last_execution_time desc

Monday, January 24, 2011

SQL Split Function


This SQL Split Function is use to SPLIT a sentences based on the Delimeter.
Delimeter is a string character used to identify substring limits.

Below is Split Function in SQL
DECLARE @NextString NVARCHAR(40)
DECLARE @Pos INT
DECLARE @NextPos INT
DECLARE @String NVARCHAR(40)
DECLARE @Delimiter NVARCHAR(40)

SET @String ='SQL,TUTORIALS'
SET @Delimiter = ','
SET @String = @String + @Delimiter
SET @Pos = charindex(@Delimiter,@String)

WHILE (@pos <> 0)
BEGIN
SET @NextString = substring(@String,1,@Pos - 1)
SELECT @NextString -- Show Results
SET @String = substring(@String,@pos+1,len(@String))
SET @pos = charindex(@Delimiter,@String)
END


Result
- SQL
- TUTORIALS

* Copy blue color Sql split function with change @String variable to test the result in your query analyzer.



Unable to connect to asp.net development server


I got this error after updating Microsoft Visual Studio 2008 Service Pack 1 (which took much longer than expected - close to two hours):

WebDev.WebServer.exe has stopped working
Unable to connect to the ASP.NET Development Server

As usual, this appeared to be a problem many people had, under many different scenarios, with many different solutions. The following solution is the solution that worked for me:

Delete the web project from the solution, rename the folder where the website is stored and then re-add the project to the solution as an existing website.

This is fine on my local laptop, but would probably be a bit more disconcerting in Visual Source Safe.

So my best guess is Visual Studio stores information about a web site somewhere.  If you don't perform the folder rename, when you add the web site back in you'll see the original, dynamic port settings.  It appears renaming forces a new port.

I don't know where this information is stored.  I can't seem to find anything in the registry, and deleting the temporary asp.net files didn't have any affect.

Although renaming the folder worked, I also did this:

The host file at %\Windows\System32\drivers\etc\hosts may have an incorrect entry. This line...

::1 localhost

was changed to...

:::1 localhost

That's three colons - not two.

I didn't experiment any further and have just moved on.


Sunday, January 2, 2011

Set Class From Javascript


//change the tab class style
var browser=navigator.appName;
var classtyp;
if(browser=='Microsoft Internet Explorer')
{
classtyp = "className";
}
else
{
classtyp = "class";
}

if (val=='new')
{
document.getElementById("liUpcoming").setAttribute(classtyp, "selectednews");
document.getElementById("liPast").setAttribute(classtyp, "");
}

Friday, December 31, 2010

Finds a Control recursively in Asp.net

On one of my project i need to Find the controls till get the result control so i have built the code like this...

Below is Method Definition :

/// <summary>
/// Finds a Control recursively. Note finds the first match and exists
/// </summary>
/// <param name="ContainerCtl"></param>
/// <param name="IdToFind"></param>
/// <returns></returns>
public static Control FindControlRecursive(Control Root, string Id)
{
string str =string.Empty;
if (Root.ID == Id)
return Root;
foreach (Control Ctl in Root.Controls)
{
Control FoundCtl = FindControlRecursive(Ctl, Id);
if (FoundCtl != null)
{
switch (Id)
{
case "hdnProductId":
staticProductId = ((System.Web.UI.HtmlControls.HtmlInputHidden)FoundCtl).Value;
break;
case "hdnProductName":
staticProductName = ((System.Web.UI.HtmlControls.HtmlInputHidden)FoundCtl).Value;
break;
}
break;
}
}
return null;
}

Below is Method Definition in GIF Format :


Below is how to call that method:-

FindControlRecursive(this.Page.Master, "hdnProductId");
FindControlRecursive(this.Page.Master, "hdnProductName");

Below is how to call that method in Gif Format:-

Wednesday, December 29, 2010

Convert month number to month name in sql

In this blog I will explain you how to convert month number to month name in sql. To explain it I have used

SELECT DATENAME( MONTH , DATEADD( MONTH , @MONTHNUMBER , 0 ) - 1 ).Below is the code snippet:


DECLARE @MONTHNUMBER INT

SET @MONTHNUMBER=1

SELECT DATENAME( MONTH , DATEADD( MONTH , @MONTHNUMBER , 0 ) - 1 ) AS [MONTHNAME]

-OUTPUT


MONTHNAME

------------------------------

January

DECLARE @MONTHNUMBER INT


SET @MONTHNUMBER=12

SELECT DATENAME( MONTH , DATEADD( MONTH , @MONTHNUMBER , 0 ) - 1 ) AS [MONTHNAME]

--OUTPUT


MONTHNAME

------------------------------

December



2 ).Below is the code snippet:

SELECT CONVERT(VARCHAR(3), DATENAME(MM, CreatedDate_ColumnName), 100)

Monday, December 27, 2010

Clear Controls in Asp.Net

Main Function to Read All controls in do action :-



Call the Method by this way. here in my first line this is multiview id i want to clear all controls under multiview, and on the second one all controls available in the page..