Tuesday, February 5, 2013

Using Pivot in SQL

Empid EmpName EmpDay empStatus
1 Bikash 1 P
2 Bikash 2 P
3 Bikash 3 P
4 Bikash 4 A
5 Bikash 5 A
6 Bikash 6 P
7 Bikash 8 P
8 Rama Rao 1 P
9 Rama Rao 2 P
10 Rama Rao 6 P
11 Rama Rao 3 P
12 Rama Rao 7 P

SELECT EMPNAME,[1],[2],[3],[4],[5],[6],[7],[8],[9] FROM (SELECT EMPNAME,EMPDAY,EMPSTATUS FROM EMPTEST) X PIVOT (MAX(EMPSTATUS) FOR EMPDAY IN([1],[2],[3],[4],[5],[6],[7],[8],[9])) Y


EMPNAME 1 2 3 4 5 6 7 8 9
Bikash P P P A A P NULL P NULL
Rama Rao P P P NULL NULL P P P NULL

DECLARE @cols AS NVARCHAR(MAX)
DECLARE@query AS NVARCHAR(MAX)
 
SET @cols = (SELECT DISTINCT ',['+ CAST(EMPDAY AS VARCHAR(10)) +']' FROM EMPTEST FOR XML PATH(''))
SELECT @cols= SUBSTRING(@COLS,2,LEN(@cols))
  SET @query = 'SELECT EMPNAME,'+@cols+' FROM
(SELECT EMPNAME,EMPDAY,EMPSTATUS FROM EMPTEST) AS X
PIVOT (MAX(EMPSTATUS) FOR EMPDAY IN('+@cols+')) P'

EXEC (@query)

Monday, October 29, 2012

Convert String in Title Case

string asTitleCase = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(txt1.Text.ToLower());

It will return "This Is Blog" from "this is blog"

Monday, May 28, 2012

ASP.NET MVC Flexigrid sample

URL : http://www.codeproject.com/Articles/30588/ASP-NET-MVC-Flexigrid-sample

How to create an ASP.NET MVC sample using LINQ to SQL, Flexigrid for JQuery, and JSON.

Wednesday, February 1, 2012

String Methods()

IndexOf(): method in string Class in C# returns the index of the first occurrence of the specified substring.
Syntax:int string.IndexOf(string str)

Integer - If the parameter String occurred as a substring in the specified String
it returns position of the first character of the substring.
If it does not occur as a substring, -1 is returned.

Example:
"This is a test".IndexOf("Test") returns 10
"This is a test".IndexOf("vb") returns -1


Clone(): method creates and returns a copy of string object. The CSharp string Clone() method returns a reference to this instance of string.

string str = "Clone() Test";
string clonedString = null;
clonedString = (String)str.Clone();


Compare(): function compares two strings lexicographically . The comparison is based on the Unicode value of each character in the string.
Syntax: int string.Compare(string str1,string str2)

It returns an Integer indication lexical relationship between the two comprehends

Integer : returns less than zero, zero or greater than zero.
Less than zero : str1 is less than str2
zero : str1 is equal to str2
Greater than zero : str1 is greater than str2


Concat(): method Concatenates the two specified string and create a new string.
Syntax: string concat(string str1,string str2)

EndsWith(): method check if the Parameter String EndsWith the Specified String
Syntax: bool string.EndsWith(string suffix)

Equals(): method is to check the specified two String Object values are same or not
Syntax: bool string.Equals(string str1,string str2)

Insert(): method will insert a String in a specified index in the String instance.
Syntax: string string.Insert(int ind,string str)
"This is Test".Insert(8,"Insert ") returns "This is Insert Test"

TryParse(): method is using for determine whether a string is a valid representation of a specified numeric type or not. TryParse method that is implemented by all primitive numeric types and also by types such as DateTime and IPAddress.
Syntax: bool int.TryParse(string param , out int result)


Substring():

string input = "OneTwoThree";

string sub = input.Substring(0, 3);
//Output : One

string sub = input.Substring(3);
//Output : TwoThree

string sub = input.Substring(3, 3);
//Output : Two

string sub = input.Substring(0, input.Length - 5);
//Output : OneTwo

string CultureInfo(): The String Class is a sealed class , so you cannot inherit another class from the String class. ToTitleCase converts the first character of a word to uppercase and the rest of the characters to lowercase.

A neutral culture is specified by only the two-letter lowercase language code. For example, "fr" specifies the neutral culture for French, and "de" specifies the neutral culture for German.

System.Globalization.CultureInfo cultureInfo = _new System.Globalization.CultureInfo("en-US");

The CultureInfo class renders culture-specific information, such as the associated language, sublanguage, country/region, calendar, and cultural conventions. The following C# source code shows how to convert a string to Title Case.

string _str = null;
System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("en-US");
_str = cultureInfo.TextInfo.ToTitleCase("make first letter capital");
MessageBox.Show (_str);

Monday, January 23, 2012

ASP Menu Control Browser Comaptibility

Use this code to your master page where ASP Menu control is used.

At Form Load
Request.Browser.Adapters.Clear();

Monday, December 19, 2011

Function Parameter Hint

There is a simple method :

/// <summary>
/// <para>strValue can have 3 values "Pass","Fail" or "NA"</para>
/// <para></para>
/// </summary>
/// <param name="strValue"></param>
public bool checkStatus(string strValue)
{
if (strValue == "Pass")
{
//do something
}
else if (strValue == "Fail")
{
//do something
}
else if (strValue == "NA")
{
//do something
}
else
{
//do something
}

return true;
}

When Call

Tuesday, November 15, 2011

FindControl in Master Page

Problem :

Page.FindControl() can be misleading. A developer without understanding the situation could assume FindControl() will return a control found within that page. This is completely wrong. The reason this does not work is because Page does not have its own FindControl() function. It actually inherits this from Control, because Page inherits control. So FindControl() is really more like a FindChildrenControls(), and it is not recursive.

Solution:

ContentPlaceHolder CPage = (ContentPlaceHolder)this.Page.Master.FindControl("ContentPlaceHolderForContent");
Label lblLabel = ((Label)(CPage.FindControl(strLabel)));