Posts

Showing posts from 2012

Difference Between ArrayList and Generic.List C#/VB.Net

Hi, Last few Days, I learnt a very basic and important thing about  that ,When one should go for ArrayList or Generic.List in coding......On basis of that, I found  few difference between both. ArrayList Its comes under System.Collections namespace. Its contains Array of Object.i.e Any objects type we can store in a ArrayList.We can store any no. of objects at runtime. ArrayList aryList= new ArrayList(); // No Need to specify the object type,can store anything arList.Add(1); arList.Add("Shubhank"); arList.Add("False"); We can store any objects in ArrayList and can retrieve only Objects from ArrayList... We can say that ArrayList is not Type-Safe .At the Time of inserting recods ,we can store any type of objects,but at the time of fetching we can't be sure that  Values  which are populate by arList (ArrayList object ) of what type..however.. we have to following code while fetching records/items from Array list foreach(Object o in arList) { ....

How to do debug in Web Services

Image
Hello All, I learnt new thing ,how to debug in Web Services, earlier i have used log (txt) to see where my services failed,but now I got new way.Hence I would like share this with all of you.... :) steps - 1) Create a new TestWebservice (File->New Project->ASP.Net Web Service Application) steps - 2) Create a public new method with [webmethod] attribute say " int return type Calculations method accepting two inputs and a calculations class (note set breakpoint in calculation method ) Services.asmx.cs Calculations.cs steps -4) Now run the web services and you will see URL in browser like  http://localhost:49623/Service1.asmx steps -5) Now create a new TestClientWebapplications a new website (File->New Project->WebSite) have a button (btncallWebserices) ,Text=CallWebService and on it click event call the web services ( before that u need to Add a Web References add url above). steps -6) Set breakpoint on btnclick event method run application and then cl

SQL Interview Questions

Image
SQL Interview Questions Q. Display names of all salesperson whose customers are john? Q. Display names of all salesperson whose customers are not john? Q. Insert   those records into a table highvale(name,age) from saleperson whose salary is 2000 or greater than ? Q.   Display name of customer who have 2 or more order ? Q. Display name of saleperson who have maximum amt in orders ? Q. Display name of saleperson,total of amt   who have maximum amt in orders ? Q.   Display 3 rd highest salary of salesperson (Assume there are 1000 records in salesperson table). Q. Difference between Delete and Truncate ? Q.   Select substr(‘shubh’,2) from dual ? Is this Query will run ? yes /No .If not then what will be correct Query ? Q.   Select Round(2.75,2) from dual, Select   trunc(2.75,2) from dual ? what will be output ? Q. Difference between CAST and Convert ? (note : both function may be or may be not in your database.So try it

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