Posts

Showing posts from January, 2012

Puzzle on Byte values addition Gives Different output in C# and VB.Net

Hello Friends ! Greetings I will show an puzzle which display different output in VB.Net and C#.Think on it. class Program { public static void main() { byte a = 100; byte b = 200; byte c= a + b; Console.Writeline(c); Console.ReadLine(); } } Now what output it will display when compile this application it gives you compile Time Error like that Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?) BUT BUT When u do the same code in VB.Net then it gives you RunTime Error."Arithmetic operation resulted in an overflow." And Interesting thing is that when you change value of a from 100 to 1 and b from 200 to 2.It will run successfully and display 3....in VB.Net. So Conclusion of Above Puzzle is that Type Casting Aspect is strongly used and recommend in C#.Developers need to take care of it Whereas in VB.Net (Considering Option strict off), it will do internally Type Casting. Suggest Me if you find any ot

Delete Duplicate Records from table which does not have primary Key

Hello friends Greetings ! I will share an interesting Query that Delete records from table which doesn't have any Key (primary Key,Unique Key ). Step 1 : Create a table named as empName run the following query CREATE TABLE [dbo].[emp]( [empId] [int] , [empName] [nvarchar](max) NULL ) Step 2 : Insert records into the table empName INSERT INTO [emp] VALUES (1,'Shubhank') INSERT INTO [emp] VALUES (2,'Viru') INSERT INTO [emp] VALUES (3,'Shubhank') INSERT INTO [emp] VALUES (4,'Maths') INSERT INTO [emp] VALUES (5,'Shubhank') INSERT INTO [emp] VALUES (6,'Shubhank') INSERT INTO [emp] VALUES (7,'Denis') INSERT INTO [emp] VALUES (8,'Gates') INSERT INTO [emp] VALUES (9,'Linux') INSERT INTO [emp] VALUES (10,'Shubhank') INSERT INTO [emp] VALUES (11,'Gary') INSERT INTO [emp] VALUES (12,'Rajkishan') INSERT INTO [emp] VALUES (13,'Shubhank') INSERT INTO [emp] VALUES (14,'Rajiv') INSERT

Week Number from date in .Net

Hello friends, I will show an example that find out week no. from date in VB.net. Step 1: Imports System.Globalization in your page. Step 2 : Now in your Page_load event of default.aspx page,paste the following code Dim ciCurr As CultureInfo = Nothing Dim intweekNo As Integer = 0 Dim intCalendarWeekRule = 0 Dim dteDate as DateTime=Now.Date Try ciCurr = CultureInfo.CurrentCulture intweekNo = ciCurr.Calendar.GetWeekOfYear(dteDate, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday) lblOutput.Text=intweekNo.ToString() Catch ex As Exception lblMessage.Text=ex.Message Finally End Try Step:3 When you run the following code you will get the weekno. of current date.

How to Use Not IN operator

Hello Friends Here i am explaining an example of NOT IN operator. Suppose you have two tables one is employee and Bademployee employee and Bademployee has relationship. Bademployee contains records who are bad Now you want to show the Good employee so following is the example Step : 1 create Table emp Run this Query in your Query Analyzer for table emp 1) CREATE TABLE [dbo].[emp]( [empId] [int] NOT NULL, [empName] [nvarchar](max) NULL, CONSTRAINT [PK_emp] PRIMARY KEY CLUSTERED ( [empId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] Now Run this Query in your Query Analyzer for table bademp CREATE TABLE [dbo].[bademp]( [empid] [int] NOT NULL, [bademp] [nvarchar](50) NOT NULL, CONSTRAINT [PK_bademp] PRIMARY KEY CLUSTERED ( [empid] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY

Examples of Self JOIN

Hello friends, Self Join is very basic thing in SQL.I am explaining it with example in SQL Server Enjoy Self JOIN Step 1 :Create a table named as employee Run the following Query CREATE TABLE [dbo].[employee]( [empId] [int] NOT NULL, [empname] [nvarchar](1200) NOT NULL, [managerid] [int] NOT NULL ) ON [PRIMARY] Step 2 : Insert data into it Insert into employee values (1,'john',1) Insert into employee values (2,'Jasmine',1) Insert into employee values (3,'Rahman',2) Insert into employee values (4,'Victor',3) Insert into employee values (5,'Majid',1) Insert into employee values (6,'Olvin',3) Insert into employee values (7,'Soniya',2) step 3 : Now ,I want the records of employees with thier manager Id and manager name so I will apply Self JOIN on employee table on empId and managerId. Check and run this Query SELECT a.empid,a.empname as EmployeeName,a.managerid as ManagerId,b.empName as ManagerName FROM employee a INNER JOIN