Saturday, September 27, 2014

Find the duplicate records with the help of CTE

with cte 
as
(
select *,ROW_NUMBER() over (partition by EmpName order by EmpId desc) Rn
from Employee
)
select * from cte where Rn=1

Wednesday, August 20, 2014

Difference between Abstract Class and Interface

1. An abstract class can have abstract members as well non abstract members. Whereas in an interface all the members are implicitly abstract.

2. A class can inherit one or more interfaces, but only one abstract class. So, with the help of Interface C# support multiple inheritance.

3. Abstract class is refererence type because it's a class. In an Interface we can't say anything until then, who is going to be implement. If a class is implement it behaves like a reference type and if a structure implement, then it behaves like value type.
e.g.  

    interface MyName                                                     
     {
         void Name();
     }

    struct StructInterface:MyName                                       public class clsInterface : MyName
    {                                                                                      {
         public void Name()                                                          public void Name()
         {                                                                                         {
             Console.Write("My Name");                                               Console.WriteLine("My Name");
         }                                                                                         }
    }                                                                                       }

4. Abstract class provide partial abstraction while Interface provide full abstraction.

5. Generally, abstract class used where, we have partially idea about the thing, that somewhere we confirm over the logic and somewhere not. But in the case of Interface we don't have any idea related the thing.





Monday, August 18, 2014

Difference between bug, error and exception

"One of the most confusing question I would say".
I have a story to simplify these three concepts:
Suppose I planned to go from India to London. Took my flight from New Delhi Airport for London. I kept in my mind the time when the flight will land in London. But when I woke-up, I was in Dubai. This is called Bug. Irrelevant result. Everything looks fine but the output is not as expected. 

Second one is ERROR: When I reached the airport to take my flight, there was some problem in the Air-Bus due to which the flight got delayed. This problem is called error and without fixing it, we are not able to execute the code. We have to fix it first.

And the last one is EXCEPTION. Let's suppose when I'm in the flight, and mid-way, all the engine of the plane stopped working due to unexpected reasons but I landed safely. Common belief would be that the plane is going to be crashed but this did not happen and all the passengers are safe. This is called EXCEPTION.  I'm still alive and running.

Same thing happens in a Program also. You don't come to know that some circumstances are generated in your program and by these circumstances, you believed that the program will surely crash/Stop but it did not happen. Because these exceptions are handled in our code.

For e.g. suppose a SQL Connection Exception Occurred and you don't know  when your database is  going to crash. By these exceptions,your program will definitely crash and a Big Yellow page will come at user's end. To manage this, we need to handle these exception in our program to run the program hassle free.

So we can say that: exception handling features provide a way to deal with any unexpected or exceptional situations that arise while a program is running.


Saturday, July 26, 2014

Connect Oracle Database with Entity Framework

With lot of efforts I have found the actual ODAC and ODT driver that provide visual studio development enviroment with oracle 10g (11g latter) and database connection.

The ODAC you can downlaod from the url:  http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html















Install this ODAC driver. Now when you add EDMX (Entity Framework) file then you get the
Oracle Data Provider For .Net.
























Select this driver fill the datasource name, user name and password.
Now you connect with  your oracle database.

Thursday, July 24, 2014

Difference between == and === (equals and triple equals)

The == and === equality operator are used in JavaScript

The === sign defines that value must be equal in type as well however == not.

Example :

0==false   // true
0===false  // false, because they are of a different type
1=="1"     // true, auto type coercion
1==="1"    // false, because they are of a different type

Code Snippet:

                    <script type="text/javascript">
                            function a() {
                               if (1 ==='1') {
                                           alert('true');
                                                   }
                              else {
                                           alert('False');
                                     }
                           }
                  </script>

ListBox Multi Select Option to Move Item in asp.net

Move Item from Left to Right List Box and Vice-Versa.



Code Snippet : 

    protected void btnRight_Click(object s, EventArgs e)
        {
            int[] indexes = this.lstLeftList.GetSelectedIndices();
            ListItem[] items = new ListItem[indexes.Length];
            for (int i = 0; i < indexes.Length; i++)
            {
                items[i] = this.lstLeftList.Items[indexes[i]];
            }

            for (int i = 0; i < items.Length; i++)
            {
                this.lstRightList.Items.Add(items[i]);
                this.lstLeftList.Items.Remove(items[i]);
            }
        }

        protected void btnLeft_Click(object s, EventArgs e)
        {
            int[] indexes = this.lstRightList.GetSelectedIndices();
            ListItem[] items = new ListItem[indexes.Length];
            for (int i = 0; i < indexes.Length; i++)
            {
                items[i] = this.lstRightList.Items[indexes[i]];
            }

            for (int i = 0; i < items.Length; i++)
            {
                this.lstLeftList.Items.Add(items[i]);
                this.lstRightList.Items.Remove(items[i]);
            }
        }

What is the difference between Server.Transfer and Response.Redirect?

Response.Redirect involves a round-trip to the server whereas Server.Transfer conserves server resources by avoiding the round-trip. It just changes the focus of the web-server to a different page and transfers the page processing to a different page.

Response.Redirect can be used to redirect a user to an external websites. Server.Transfer can be used only on sites running on the same server. You cannot use Server.Transfer to redirect the user to a page running on a different server.

Response.Redirect changes the url in the browser. Whereas Server.Transfer retains the original url in the browser. It just replaces the contents of the previous page with the new one.