Posts

Showing posts from 2010

Append Characters to Left of any String -- Use of PadLeft function

Hello everyone ! I heard the function of padLeft,padright in my college.I thought , what is the need of this function, where we used it.I skip this function and called it "useless". but at the time of programming in VS.Net , i got a issue that is To append zeros at left side of a string say "61" and its should be 10 digit string like that "0000000061" then, I start coding ,try to applying "***for if,,,,while & logic****** Select Case**** ". Result : Partially successful , but code was not feasible,reliable....in short.. fail ! Then, while solving the online practice test ,i got the questions of padleft .I was clueless,and remember my carelessness. I got a clue from that test,also got an idea that i can use this function for appending any character to a string at right side or left side of it. So suppose you have string say "61", and you want make it 10 digits string, with zero's at leftside then use padleft function. st

Check Type of Object at Runtime in C#

If You want to check the TYPE of an object at runtime in C# then you have to use IS Keyword example : using System; class CApp { public static void Main() { string s = "Shubhank"; long i = 900; Console.WriteLine( "{0} is {1}an integer", s, (IsIntegerType(s) ? "" : "not ") ); Console.WriteLine( "{0} is {1}an integer", i, (IsIntegerType(i) ? "" : "not ") ); } static bool IsIntegerType( object obj ) { if( obj is int || obj is long ) return true; else return false; } } Output will be Shubhank is not an integer 900 is an integer

Find nth Highest Salary from Employee Table

How to Find 2nd ,3rd or upto....Nth highest Salary of any employee in SQl Step 1 Create Table Create Table emp ( empName nvarchar(max), Salary int ) Step 2 Insert records 1 ) Insert into values emp ('John',2000) 2 ) Insert into values emp ('Kim',5000) 3 ) Insert into values emp ('Walter',1500) 4 ) Insert into values emp ('Obama',3000) 5 ) Insert into values emp ('John Vincet',2500) 6 ) Insert into values emp ('Womek',3500) Step 3 Query Find the 2nd Highest Salary from emp Table Select * from emp a Where (2=(Select Count(Distinct b.Salary) from emp b Where b.Salary >= a.Salary)) Step 4 Execute the Step 3 Query Step 5 For find the nth Highest Salary from emp Table Select * from emp a Where (n=(Select Distinct(b.Salary) from emp b Where b.Salary >= a.Salary)) Step 6 Check the Ouptut..

String Function in SQL-Substring,Reverse,CharIndex

Suppose You have String "~/ABC/PQR.xxx" in your tables Now u Want to string PQR.xxx fromm above string So For That Follow the Steps 1) Open NewQuery Window 2) Paste following Code declare @str as varchar(200),@str1 as varchar(200),@rev as varchar(200) set @str ='~/ABC/PQR.xxx' select @rev = reverse(@str) SELECT @str1 = CHARINDEX('/', reverse(@str)) select @str1,@rev'@rev',reverse(substring(@rev,0,convert(int,@str1))) 3) Execute the Code 4) You will get the Output Like that PQR.xxx

Validate Email Id Using Web Serivces

To Verified the Specified Email ID , use ValidateEmail.asmx Id Web - Services Steps are : 1) Create a Demo Web Application(TestEmail Id). 2) Take Textbox (txtEmaildId) and Button( btnCheck) and Label (lblStatus ) from ToolBox on Demo.aspx 3) Now, Right Click on Your Solution, Click on Add Web-Referneces 4) Paste this URL on Pop-up Window http://www.webservicex.net/ValidateEmail.asmx?wsdl 5) Click on Add References Button 6) Write the following code on click Event of button(btnCheck) net.webservicex.www.ValidateEmail a = new net.webservicex.www.ValidateEmail(); bool result=a.IsValidEmail("txtEmaildId.Text"); if (bool == true) { lblstatus.Text = "Valid Email Id"; } else { lblstatus.Text = "Invalid Valid Email Id"; } 8) Run the Application and check status of Label 9) Insert email id say a@c.com , then check status 10 Now Insert email id existing Email Id , then check status Enjoy Valid Email Id Code Using Web-Services