Tuesday, September 18, 2012

Moving value from one ListBox to another ListBox using C#.NET

First the ListBox declaration set the SelectionMode=”Multiple”.

For more details, you can visit on below link.


<td class="call2">

  <asp:ListBox ID=" ListBox1" runat="server" SelectionMode="Multiple"></asp:ListBox>
<td class="call1">
  <asp:Button ID="btnadd" runat="server" Text=">>" OnClick="btnadd_Click"    />
                    <br />
 <asp:Button ID="btnsubtract" runat="server" Text="<<" OnClick="btnsubtract_Click" />
<td class="call2">
  <asp:ListBox ID=" ListBox2" runat="server" SelectionMode="Multiple"></asp:ListBox>

For adding items in the list
   protected void btnadd_Click(object sender, EventArgs e)
        for (int i = ListBox1.Items.Count - 1; i >= 0; i--)
            if (ListBox1.Items[i].Selected)

 For removing items in the list
    protected void btnsubtract_Click(object sender, EventArgs e)
        for (int i = ListBox2.Items.Count - 1; i >= 0; i--)
            if (listBoxSelectedEmp.Items[i].Selected)


Wednesday, September 12, 2012

Difference between varchar and nvarchar in SQL server

1. Character Data Type

  •        varchar - Non-Unicode Data
  •        nvarchar - Unicode Data

2. Character Size

  •          varchar - 1 byte
  •          nvarchar - 2 bytes

3.  Maximum Length

  •          varchar - 8,000 bytes
  •          nvarchar - 4,000 bytes

4.  Storage Size

  •          varchar - Actual Length (in bytes)
  •          nvarchar - 2 times Actual Length (in bytes)

Monday, September 10, 2012

difference between mvc 2 and mvc 3 in asp.net

.aspx view engine
.cshtml view engine
There is no life cycle in mvc page.
There is no life cycle in mvc page.
Have TempData, ViewData
Supported by ViewBag
No have ! Chart, WebGrid, WebImage, WebMail
Its have Chart, WebGrid, WebImage, WebMail
It have <%=Html code %>
But @Html code
Don’t write the c# code within View engine page.  
write the c# code within View engine page.   

Boxing and Unboxing in C#


Boxing is implicit conversion. The Main purpose of Boxing is used to convert value types into reference type or object type and store in the heap.

     Example: int i = 1;

Boxing a value type allocates an object instance on the heap and copies the value into the new object. 

     Example: // Boxing copies the value of i into object o.
                 object o = i; 

The result of this statement is creating an object reference o, on the stack, that references a value of the type int, on the heap. 

This value is a copy of the value-type value assigned to the variable i.

It also possible to perform the boxing explicitly as in the following 

Example, but explicit boxing is never used.

int i = 1;
object o = (object)i;  // explicit boxing


public class TestBoxing
    public static void Main()
        int i = 1;
        // Boxing copies the value of i into object o. 
        object o = i;  
        // Change the value of i.
        i = 4;  
        // The change in i does not effect the value stored in o.
        Console.WriteLine("The value-type value =", i);
        Console.WriteLine("The object-type value =", o);
/* Output:
    The value-type value = 4
    The object-type value = 1


Unboxing is an explicit conversion. The Main purpose of Un-Boxing is used to convert the object type or reference type to a value type and store in the stack.

                                 int i = 1;       // a value type 
                       object o = i;    // boxing (implicit conversion)
                       int j = (int)o;  // Unboxing (explicit conversion) 


Friday, September 7, 2012

How to remove duplicate rows in SQL Server

delete from dbo.tblSalary
           where emp_salary in(
                  select emp_salary as [Salary Result] from dbo.tblSalary
                                    group by emp_salary
                                    having count(emp_salary)>1)

Noted point: dbo.tblSalary =Table-Name”
      emp_salary = “Column-Name”