Wednesday 31 October 2012

Changed PC or laptop password without knowing previous password.

Hi friend's , I have explained here how to change your pc or laptop password without knowing your previous password. By using this method you can also change your friends pc password without knowing his /her pc password.

open command promt -> type net user ->list of  user name will come -> which user's password you want to change -> type net user  name_of_user_you_want_to_change * -> click enter -> it will show command completed successfully.

for Ex:- c:\Users\sushil\ net user  sushil *  // not forget * 


Monday 29 October 2012

What is Difference between Class and Structure in C#.


Class:
1.)Class is reference type . Instance of a class are stored on the heap.
2.)It  support all the OOP’S concept.
3.)It has an explicit default constructor.
4.) Field is initialized when they are declared in the class.

Structure:
1.) Structure is value type. Instance of structure are stored on stack area.
2.)It doesn’t support inheritance.
3.)It cannot have explicit default constructor.
4.) Fields cannot be initialized when they are declared in the structure.

Sunday 28 October 2012

How to Show table data using Linq To Sql in Asp.Net using C#.


I am continuing  to write the post on Linq. Here I have explained  how to perform crude operation  using Linq To Sql using c#.
If you don’t have  Sql Server Express then you can download from Here.
Launch Visual studio and open new web site . After this right click on project application -> add new items -> select linq to sql file -> named it whatever you want  -> click ok.
Drag and drop gridview on Design page.
Code Behind Default.aspx page:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class linq : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        NorthwindDataContext nwdc = new NorthwindDataContext();

        var emp = from myemp in nwdc.Employees
                   select myemp;


        GridView1.DataSource = emp;
        GridView1.DataBind();
       

    }
}
Press F5 and see the result. In next post I will add new thing about linq. 

New Three Tire Architecture in Asp.Net using C Sharp


Basically three tire architecture contains  three different layers:
1.)Application Layer or Presentation Layer
2.)Bussiness logic layer or Bussiness Access layer(BAL)
3.)Data logic layer or Data Access Layer(DAL)
Use of 3 tire architecture:
1.)  Easy to understand
2.) Easy to maintain ,easy to manipulate and easy to  modify.
Here  I have explained   step by step  so that anyone can understand the logic in simple way.
Apllication Layer:
It is nothing but just a design page means  how will   your page look . You can design your page in your own way . Design coding is given below.
Home.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Home.aspx.cs" Inherits="Home" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Home</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:Label ID="Label1" runat="server" Text="username"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
        <asp:Label ID="Label2" runat="server" Text="Password"></asp:Label>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
        <asp:Label ID="Label3" runat="server" Text="First Name"></asp:Label>
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
        <asp:Label ID="Label4" runat="server" Text="Last Name"></asp:Label>
        <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br />
        <asp:Label ID="Label5" runat="server" Text="Email"></asp:Label>
        <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox><br />
        <asp:Label ID="Label6" runat="server" Text="Phone No"></asp:Label>
        <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox><br />
        <asp:Label ID="Label7" runat="server" Text="Location"></asp:Label>
        <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox><br />
       
        <asp:Button ID="Button1" runat="server" Text="Register"
            onclick="Button1_Click" />
    </div>
    </form>
</body>
</html>

After this will discuss about Bussiness logic layer.
This layer is used as interface between the aplliacrion layer and Data Access layer.
How to add this layer.
Right click on your project application-> add new items -> select class file-> give it name as BAL.cs.
One folder created with App_code name.
Again right click on App_code -> select new items -> select class file and give a name BEL.cs.

Code For BEL.cs:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for BEL
/// </summary>
public class BEL
{
      public BEL()
      {
            //
            // TODO: Add constructor logic here
            //
    }
    #region Variables
    /// <summary>
    /// User Registration Variables
    /// </summary>
    private string _UserName;
    private string _Password;
    private string _FirstName;
    private string _LastName;
    private string _Email;
    private string _Phoneno;
    private string _Location;
    
    #endregion
    public string UserName
    {
        get { return _UserName; }
        set { _UserName = value; }
    }
    public string Password
    {
        get { return _Password; }
        set { _Password = value; }
    }
    public string FirstName
    {
        get { return _FirstName; }
        set { _FirstName = value; }
    }
    public string LastName
    {
        get { return _LastName; }
        set { _LastName = value; }
    }
    public string Email
    {
        get { return _Email; }
        set { _Email = value; }
    }
    public string Phoneno
    {
        get { return _Phoneno; }
        set { _Phoneno = value; }
    }
    public string Location
    {
        get { return _Location; }
        set { _Location = value; }
    }
}

Code for  BAL.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for BAL
/// </summary>
public class BAL
{
      public BAL()
      {
            //
            // TODO: Add constructor logic here
            //
    }
    #region Insert UserInformationDetails
    public string InsertUserDetails(BEL objUserDetails)
    {
        DAL _objUserDAL = new DAL();
        try
        {
            return _objUserDAL.InsertUserInformation(objUserDetails);
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            _objUserDAL = null;
        }
    }
    #endregion
}

Data Access Layer:
Data Access layer contains method , is used to connect with DataBase and perform insert ,update and delete operations.
Code for DAL.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

/// <summary>
/// Summary description for DAL
/// </summary>
public class DAL
{
      public DAL()
      {
            //
            // TODO: Add constructor logic here
            //
      }
    string ConnectionString = ConfigurationManager.ConnectionStrings["Connection"].ToString();
    public string InsertUserInformation(BEL objBELUserDetails)
    {
        SqlConnection con = new SqlConnection(ConnectionString);
        con.Open();
        SqlCommand cmd = new SqlCommand("sp_user_registration", con);
        cmd.CommandType = CommandType.StoredProcedure;
        try
        {
            cmd.Parameters.AddWithValue("@UserName", objBELUserDetails.UserName);
            cmd.Parameters.AddWithValue("@Password", objBELUserDetails.Password);
            cmd.Parameters.AddWithValue("@FirstName", objBELUserDetails.FirstName);
            cmd.Parameters.AddWithValue("@LastName", objBELUserDetails.LastName);
            cmd.Parameters.AddWithValue("@Email", objBELUserDetails.Email);
            cmd.Parameters.AddWithValue("@PhoneNo", objBELUserDetails.Phoneno);
            cmd.Parameters.AddWithValue("@Location", objBELUserDetails.Location);
           
            //cmd.Parameters.Add("@ERROR", SqlDbType.Char, 500);
            //cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;
            cmd.ExecuteNonQuery();
         // string strMessage = (string)cmd.Parameters["@ERROR"].Value;
            string strMessage = "Any Message";
            con.Close();
            return strMessage;
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            cmd.Dispose();
            con.Close();
            con.Dispose();
        }
    }
}

Now Data  Access layer and Bussiness logic layer is ready. This time for coding inside the Home.aspx.cs page.
Code for Home.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Home : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string output = string.Empty;
        BEL _objbel = new BEL();
        _objbel.UserName = TextBox1.Text;
        _objbel.Password = TextBox2.Text;
        _objbel.FirstName = TextBox3.Text;
        _objbel.LastName = TextBox4.Text;
        _objbel.Email = TextBox5.Text;
        _objbel.Phoneno = TextBox6.Text;
        _objbel.Location = TextBox7.Text;
       
        BAL _objbal = new BAL();
        output = _objbal.InsertUserDetails(_objbel);
    }
}

Now all the process is completed, so it’s time to run the project. If any problem regarding this project you can contact me at sushilct86@gmail.com or give a comment . 

How to show the table data with Gridview in asp.net using c#.


First  Know what is gridview. Gridview  is the part of ADO.NET  which is used for displaying the table data on web page  and crude operation like insert ,update and delete.
First create a table  in database .
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Employee](
      [ID] [int] IDENTITY(1,1) NOT NULL,
      [Name] [nvarchar](50) NOT NULL,
      [Password] [nvarchar](50) NOT NULL,
      [City] [varchar] NOT NULL
     
 CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED
(
      [ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
Execute this code.
Now open a new website in visual studio and give a name .
Open the Default.aspx page and drag and drop the gridview form toolbar on design page(default.aspx).
 Code  for Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" ShowFooter="True">
            <Columns>
                <asp:TemplateField HeaderText ="ID">
                <ItemTemplate >
                <asp:Label ID ="lbl1" runat ="server" Text ='<%#Eval("ID")%>' />
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Name">
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%#Eval("Name")%>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Password">
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%#Eval("Password")%>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="City">
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%#Eval("City")%>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
   
    </div>
    </form>
</body>
</html>

Code for Default.aspx.cs:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data Source=Server_name;Initial Catalog=DataBase_Name; Integrated Security=True");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            gdbind();
        }
    }
    public void gdbind()
    {
        con.Open();
        SqlCommand com = new SqlCommand("select * from Employee",con  );
        SqlDataAdapter da = new SqlDataAdapter(com);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
        con.Close();
    }
}

Press F5 button. This will show the table data on web page.
If any query regarding this you can contact on sushilct86@gmail.com or write a comment for this post. 

What is Access Modifier? How many types of Access modifiers.


Access Modifier is a c sharp keyword. It is used for level of accessibility or scope of a class or its member.In other word , access modifier specifies the portion of program in which  class and its member can be legally used. With the help of access modifiers , we can either restrict or permit the class or its member.
There are four  types of Access modifiers:
1.)private:  Member that are defined with this access modifier are accessible within the class in which they are defined. Such member are not accessed outside the class.
2.)public:  Class or member that are defined with this access modifier are accessible anywhere in the program or application. These member  can be accessed  within the class, out the class and anywhere in the program or application.
3.)protected: Member  or class that are defined with this access modifier are accessible anywhere in the own class and its derived class. Such members can be consider in between the public and private access modifiers.
4.)internal:  Class or member that are defined with this modifier are accessible in the current assembly. This modifier is considered to be equivalent to the friend access modifier in c++.

What is Delegates ? Explanation with simple example.


      This is the most powerful  and exciting new feature of c# or c sharp. This concept , the core of object oriented programming , allows you to worry more about the flow of the system at lowest level, without worrying about the specifics of individual tasks that will be handled.
    What does delegate means? In UK,USA  ,people elect their  delegates to represent their legislature or council. These Delegates represent the entire nation or state because it is impossible if the entire populations were to present to represent countries. In short ,you can say delegates is like as  function pointer  in c or c++.

What is Function pointer?
Function pointer is pointer .i.e variable , which point to the address to the function.
In other word we define delegates  “ it allows us to reference of method.”
Types Of Delegates:
There are two types of delegates:-
1.)Single cast delegates
2.)Multiple cast delegates

Syntax of Delegate:
1.)Single cast delegates:
public  Delegate <return  type>   <delegate_name>(parameters)
2.)Multiple cast delegates:
public Delegate void  <delegate_name >(parameters)

Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Delegate
{
    public delegate int Delg(int x,int y);
    public class Math
    {
        public static int Add(int x,int y)
        {
            return x + y;
        }
        public static int Mul(int x,int y)
        {
            return x * y;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Delg  del = new Delg(Math.Add );
            int add = del(7,7);
            Console.WriteLine(add);
            Delg del1 = new Delg(Math .Mul );
            int mul1 = del1(5,6);
            Console.WriteLine(mul1);
            Console.ReadLine();
        }
    }
}


Advantages of Delegates:
Dynamic binding can be done by using delegate because we can call more than one method at a time dynamically by calling the delegate in which method is defined.
Static delegate is used for delegate  without  creating a local delegate instant. Just pass in the static delegate of class.
Disadvantage of delegate:
The problem with static delegate that it must be instantiated whether they are in use or not.