Monday, January 2, 2012

Visual Styles-related operation resulted in an error because no visual style is currently active

This issue will come when we developed a windows application in windows xp and trying to run ha in windows server os ,then it will not support that themes of windows classic .

To resolve this issue

1: Run->services.msc-->Themes-->Start(Automatic)
2:ControlPanel-->Display-->Appearance-->SelectWindows XP Theme.



Different Sql query for DateFormat

1:To convert 280908(ddmmyy) to 2008-09-28 00:00:00.000

 a- SELECT CONVERT(DATETIME, STUFF(STUFF('280908',3,0,'/'),6,0,'/'), 3)
 b- declare @tst Varchar(6)
     Set @tst = '280908'
     Select cast(substring(@tst,3,2) + '/' + left(@tst,2) + '/' + right(@tst,2) as datetime)


2:Number of weeks between two different dates

SQL :SELECT DATEDIFF (ww, '01/01/1753', '12/31/9999');  

ORACLE:SELECT floor(
             (to_date('12/31/9999','mm/dd/yyyy')
              - to_date('01/01/1753','mm/dd/yyyy')
             )
             / 7) diff
FROM DUAL;
 

Remove Duplicates in List

List list = new List(new string[] { "cat", "Dog", "parrot", "dog", "parrot", "goat", "parrot", "horse", "goat" });
Dictionary wordCount = new Dictionary();

//count them all:
list.ForEach(word =>
{
string key = word.ToLower();
if (!wordCount.ContainsKey(key))
wordCount.Add(key, 0);
wordCount[key]++;
});

//remove words appearing only once:
wordCount.Keys.ToList().FindAll(word => wordCount[word] == 1).ForEach(key => wordCount.Remove(key));

Console.WriteLine(string.Format("Found {0} duplicates in the list:", wordCount.Count));
wordCount.Keys.ToList().ForEach(key => Console.WriteLine(string.Format("{0} appears {1} times", key, wordCount[key])));

Automatic Timeout in Session

To Implement auto redirection after session expires....
do the following:

Write this code in to the masterpage's cs file

protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
this.HeadContent.Controls.Add(new LiteralControl(
String.Format("",
SessionTimeOutWithin * 60, PageToSentAfterSessionTimeOut)));
}


Now also add below methods in masterpage...

public string PageToSentAfterSessionTimeOut
{
get { return "CheckSessionTimeOut.aspx"; }
}

public int SessionTimeOutWithin
{
get { return Session.Timeout; }
}

Now in WebConfig set the timeout.
Here I have set timeout to 1 minute for checking purpose....
please change it as per your requirement.

sessionState mode="InProc" cookieless="true" timeout="1">