Thursday 28 March 2013

Radio Button and Check Box


This two controls will be used when we want to provide the user with the list of values to choose from.The difference between these two controls is, radio button control is used when only a single value has to be selected from the list whereas check box is used when we want to provide multiple values to choose from list.
As a radio button supports single selection only once we select the second radio button automatically the first one gets deselected. But if we have requirement of using radio button under different places or option we need to group radio buttons by placing them on a separate container like panel, groupbox etc so that one radio button can be selected from each group.

Checked is a property provided by radio buttons and check box control to identify which control has been selected its a Boolean property that returns true if the control is not selected.

Tuesday 26 March 2013

Creating ASP.Net Web Pages

An ASP.Net web page must have page directive at the page based on which  the web server  IIS identifies that  it is an ASP.Net page and it is also use to specify which language you want to use to write the code for ASP.Net web page.

Page Directive
<% @ page language="cs/vb"%>

An ASP.Net web page can contain HTML element, Java Script, CSS and Server Side code written using C#.Net or Vb.net language.

Server Side Code(for Single statement)
To write server side code using C#.Net or VB.Net language use the following syntax:
  <>%=stmt%>

Server Side Code(for multiple statement)
  <%
      stmt1
      stmt2
      .....
%>

Server side code(for creating reusable functions)
<script language="cs/vb" runat="server">
</script>

Monday 25 March 2013

Practiced writing Windows Application code using Notepad

Today, I practiced adding new forms in Windows Application, Setting properties to controls and defining event procedure manually by writing the code in Notepad.

When we use Visual Studio we are already provided with Tool Box on the left hand side of the VS. But while creating Windows Application using Notepad we need to write each and every code for placing a control on the form for setting the properties etc like BackColor, Size,Location etc.

Whenever we st a value to any property of a control under property window Visual Studio on behalf of us writes all necessary code by assigning values to the property. This code is available in the Designer.cs file. But when we write code manually the programmer himself need to write all necessary code.

ASP (Active Server Pages)

The name Asp.Net, ASP represents a dll file with the name ASP.DLL and .Net represents .Net framework.

Asp.Net is the technology available in .Net for developing Web Applications. Asp.Net is only technology and not a language hence it requires C#Net or VB.Net language for writing the code.

Web Server 
Web Server is the software i.e responsible for the following :
  • Contain all files related to your website.
  • Provide security for the webpages related to your website.
  • Accept request from the client, in the form of http request.
  • Provide response to the client in the form of http response and provide communication with others servers like database server and email server.

What happens when we double click on an event of a control in the property window ?

When we double click on an event in a property window internally a method gets generated for writing the code and this method  has a special name  Event procedure which is block of code i.e bound with an event of control and gets executed whenever an event occurs.

The code written under event procedure will be executed by the event when it occurs taking the help of a delegate.
Whenever the event occurs it will call the delegate which then execute the event procedure that it bound with the event. Because a delegate is responsible for the  execution of event procedure first the event,delegate and the event procedure should be bound with each other as following :

Syntax:
<control><event> +=new <delegate> (<event proc>)

Example :
 this.Load += new EventHandler(Form 3 Load); 

Events and delegates are predefined under BCL(evens are defined in control classes and delegates are defined under namespace) what is defined here is only an Event procedure.

After defining a Event procedure in Form class Visual Studio links the Event ,delegate and event procedure.

Note : One delegate can be used by multiple events to execute event procedure but all events will not use the same delegates where different events may use different delegates to  execute event procedures.

Sunday 24 March 2013

Properties And Events

 
 Properties
  • Every control has a properties, events to access the properties of control Visual Studio provides Property window that lists all properties of control. To select press F4 to open it.
  • We can change any property value in the list of property under property window like width, height, font, fore color etc for which we can see the impact immediately after changing the property value.
  • Whenever we set a value to any property of a control under property window Visual Studio on behalf of us writes all the necessary code by assigning values to the property we have modified, we can view that code under Initialize Component method of a class which is called in a constructor of a class.
  • To view code under Initialize Component method ,go to definition code view right click on the method called in constructor and select go to definition this takes us to form.designer.cs and here also we find the same class because it is partial. 
Events
  • This are time period which tells when an action is to be performed i.e when exactly we want to execute a method . Every control has number of events with it where each event occurs at a particular time period.
  • We can access the events of a control also  under property window only to view them in the property window.
  • If we want to write any code that should execute when an event occurs double-click on the desired event corresponding to a control which takes you to the code view and provides a method for writing a code.
  

Thursday 21 March 2013

Cascading Style Sheet (CSS)

CSS is recommended to design the layout of the page including position of the element, appearance of the element n HTML. CSS can  be specified as inline CSS, Internal CSS and External CSS.
  • Inline CSS : Specifying a CSS style by string style attribute of HTML elements without defining it separately is called as Inline CSS. 
Eg: The following example changes font and color of the heading level h1 using Inline CSS.

<!doctype html>
<html>
<body>
<h1 style= "font-family:arial black; color:blue">
Inforica Pvt lmd
</h1>
</body>
</html>
  • Internal CSS : When CSS styles are defined within the head section then it is called as Internal CSS. While defining CSS in the head section. CSS style will have three main parts- Selector, Property and Value. Selector is used to specify the HTML element for which you are defining the style. property is used to specify the CSS property you want to set and value is used to specify the value for CSS property. Property and its value must be separated by colon and multiple properties must be separated by semicolon.
Eg: The following example defines styles for the elements h1 and h2 as internal CSS.

<!doctype html>
<html>
<head>
<style type = "text/CSS">
<h1>
{
font-family:arial black; color:blue"
}
<h2>
{
font-family:times new roman; color:red"
}
</style>
</head>
<body>
<h1> Inforica Pvt lmt </h1>
<h2> Inforica Pvt lmt </h2>
<h1> Inforica Pvt lmt </h1>
<h1> Inforica Pvt lmt </h1>
</body>
</html>
  • External CSS : Defining the CSS styles in seperate files with extention .CSS is called as external CSS. Advantages of external CSS is that they can be used in any HTM document. To add the reference the External CSS file use style element with src attributes or the link element withen the head section.
Syntax:  <style src = "Filename.css">
             <link rel = "stylesheet" type="text/css">
             href="Filename.css"


Partial Classes

  • They are introduced in C# 2.0 which allows us to define a class on multiple files ie we can physically split a class and put it into different files.

          parts.cs                                                          parts1.cs
         class parts                                                       partial class part{
        {                                                                      method1()
         method1()                                                       method2()
         method2()                                                       }
         method3()                                                      parts2.cs
        method4()                                                       partial class parts{                                           
        }                                                                    method3()
                                                                              method4()
                                                                              }
  • In the above case, the class which is defined in left hand side is redefined using the approach of partial classes wherein in this approach the class is physically separated parts logically it is one single unit ie in both the two cases when we create object of class arts we can access all the methods of the class.
  •  if  we want to define partial class in all the files the class name must be same to tell that this is one class only and moreover we need to use a partial modifier on the class in each and every file.
  • In case of partial class if we want to inherit the class from any other class it will be sufficient if we perform inheritance in one file so that it takes to a complete class
The advantages if defining partial classes are:
  • It allow splitting huge volumes of code into separate files so that managing becomes much easier.
  • Multiple programmers can work on the same class at the same time.

Wednesday 20 March 2013

HTML(Hypertext Markup Language)

HTML is a presentation language use to present web pages in the browser.HTML is made up of predefined elements and each elements has opening and closing tags and both opening and closing tags must be enclosed in angle brackets.Closing tags must have  the prefix slash(/). HTML is not case sensitive but recommended to write in lower case.

Basic elements of HTML:
  • <html></html>
HTML page must start with opening tag of  <html> and must end with closing tag of </html>
  • <head></head>
This element is use to provide a title for the page, write information related to the page like author of the page. Keywords based on which search engine can find your page and whether or not to refreash the page at specified intervals.
  • <title></title>
This element is used to provide a title for the document which will be displayed within the title bar of the browser. This elements must be inside the heads element.
  • <body></body>
This element is used to specify the actual content to display on the page.
  • Formatting Elements
<h1></h1>
<h2></h2>
<h3></h3> 
<h4></h4>  
<h5></h5> 
<h6></h6> 

This elements are use to create headings from level 1 to the level 6 where level 1 font will be large and from there font size will decrease as the level increase.
  • <p></p>
This element is used to create a paragraph text.
  • <b></b>
Use to make text as bold.
  • <i></i>
Use to make text as italic.

Monday 18 March 2013

Thread locking or Thread Synchronization

In the below Program all the three threads that are created in program are calling the same method for execution at the same time. So in this case if we execute the program and watch the output we will result that are unexpected.
The problem behind the execution is write now the method is a asynchronous method which can be called by multiple threads at a time.
To overcome the problem with asynchronous we need to first make the method as a synchronous method by adopting the process of thread locking or thread synchronous which can be done putting the methods under the special 'lock' block.
Uncomment the commented section and watch the output.

using System;
using System.Threading;


namespace CSharpConsole
{
    class ThreadDemo4
    {
        Thread t1, t2, t3;
        public ThreadDemo4()
        {
            t1 = new Thread(Display);
            t2 = new Thread(Display);
            t3 = new Thread(Display);
            t1.Start(); t2.Start(); t3.Start();

        }
        // Asynchronous Method
        public void Display()
        {
            Console.WriteLine("[CSharp is  ");
            Thread.Sleep(5000);
            Console.WriteLine("Object Oriented]");

        }
        /* Synchronous Method
        public void Display()
        {
            lock (this)
            {
                Console.Write("[ CSharp is ");
                Thread.Sleep(5000);
                Console.WriteLine("Object Oriented ]");
            }
        }*/
 
            static void Main()
        {
            ThreadDemo4 obj = new ThreadDemo4();
            obj.t1.Join(); obj.t2.Join(); obj.t3.Join();
            Console.ReadLine();
        }

    }
    
}

Windows Programming

     In development of any application we need a user interface(UI) to communicate with the end users where UI's are of 2 types
  • Character User Interface  (CUI)
  • Graphical User Interface (GUI)
     Traditionally we have only CUI. Ex Dos,UNIX,etc. where these application suffers from 2 criticisms like they are not user friendly because we need to learn the commands first to use them. They donot alow to navigate from one place to another
     To solve these problems in early 90's GUI applications were introduced by Microsoft with its windows OS which has a beautiful feature known as look and feel.
     To develop GUI's Microsoft has provided a language also in 90's only ie Visual Basic. Later when .net was introduced the support for GUI has been given in all .net languages.

Developing GUI's
     To develop a GUI we need some special components known as controls which are provided in .net languages in classes in System.Windows.form namespace. All control's which are present under this namespace were grouped into different categories
  • Common Controls
  • Container Controls
  • Menu and Toolbar Controls
  • Dialog Controls
  • Reporting Controls
  • Printing Controls
  • Data Controls
Whatever the control is, every control has 3 things in common
  • Properties: These are attributes of the control which have their impact on look of the control. Ex: Width, Height, Back-color, Fore-color etc.
  • Methods: These are actions performed by the control.  Ex: Clear(), Focus(), Close() etc.
  • Events: These are time periods which specifies when an action has to be performed. Ex: Click, Load, Keypress, MouseOver etc

Friday 15 March 2013

Multithreading in C#

  • It is an approach which allows a single program to perform multiple actions simultaneously.  Earlier we had an approach of multitasking where in this case we can execute multiple programs at a given point of time. Operating system is responsible for multitasking where all operating systems are not multitasking Operating system. Windows. MAC, Linux are multitasking Operating systems whereas DOS is a single tasking Operating system. If we want to develop a multithreaded application first the support should be available under the programming language whereas the language will internally take the support of Operating system again. C# language supports multitasking.
  • A thread is a unit of execution which is responsible in executing the program known as main thread. So by default every language is multithreaded.
  • In a single threaded program the execution takes place by performing its actions one by one ie suppose it has started calling a method until and unless that method execution is completed it cannot go to the other methods for execution. So if at all a method is taking more time to execute than the expected until that time all the other methods has to wait.
  • to overcome the problems with single threaded applications, multithreading was designed wherein multithreading we can use a separate thread for calling each method.

  • Multithreading has been designed for maximum utilization of CPU resources. So multithreaded applications execute adopting 2 principals.
  1. Time Sharing: Here Operating system allocates time period for each thread for executing the methods and transfers the control to another thread once the time is elapsed giving equal importance for all the threads to execute.
  2. Maximum utilization of resources: This comes into picture only if the first principal violates ie if a thread could not execute in its given time period for some reason without wasting at that thread Operating system transfers the control to the other threads in execution.

How to define an exception class ?

If we want to define an exception class we  need to adopt the following process:
  1. Define a class by inheriting from predefined class exception so that a new class is also an exception.
  2. Overwrite the message properly and provide the error message that has to be given when the exception occurred.
Add a new class DivideByOddNoException and  write the following code:

 
using System;

namespace CSharpConsole
{
    class DivideByOddNoException: Exception 
    {
        public override string Message
        {
            get
            {
                return "Attempted to divide by odd number ";
            }
        }
   }
}
 Add a new class ThrowDemo.cs and write the following code:

using System;

namespace CSharpConsole
{
    class ThrowDemo
    {
        static void Main()
        {
            int x, y, z;
            Console.Write("Enter x value ");
            x = int.Parse(Console.ReadLine());
            Console.Write("Enter y value ");
            y = int.Parse(Console.ReadLine());
            if (y % 2 > 0)
            {
                throw new DivideByOddNoException();
                //throw new ApplicationException("Divisor should not be an odd number ");
            }
            z = x / y;
            Console.WriteLine(z);
            Console.WriteLine("End of program ");
        }
    }
}

Wednesday 13 March 2013

Exceptions in C#

When we write a program there are chances of coming across 2 different types of errors
  • Compile-time Errors
  • Run-time Errors.
An error which comes into picture at the time of program compilation is a compile-time error which may occur due to syntax mistakes. An error which occurs in the middle of the programs execution is known as a run-time error and these errors occur due to various reasons like wrong implementation of logic, wrong inputs supplied to a program, missing of required resources etc. 
A compile-time error is not dangerous because it occurs at the time of compilation whereas run-time errors are dangerous because they occur in the program when the execution is going on and if at all a run-time error occurs in a program, the program terminates abnormally on the same line where the error gets occured without executing the rest of the code.

Note:  Whenever an error situation occurs in a program the exception handler comes into picture to identify the type of error and then creates an object of an exception class associated with that error and throws that object and that object will first terminate the program abnormally and then displays an error message associated with an exception object.

Exception Handling

Whenever a run- time error occurs under the program abnormal termination is occuring so we will be facing so many problems in the application. To overcome the problems we are provided with a mechanism known as Exception Handling.

Exception Handling is a process of stopping the abnormal termination of the program whenever the exceptions are terminating the program in case of run time error. If we can stop the abnormal termination of a program we will be getting following advantages :
  • We can make the statement which are not associated with the error.
  • We can display a user friendly error message to the end user so that he can resolve the error, got occurred provided if it is in his hands.
  • We can also perform some corrective actions to come out of a problems that may occur due to error.
To handle an exception we need to enclose our code under some special blocks known as try catch block which should be used as following:

try
{
-statements which requires execution when the run time error occurs.
-statements which does not require execution only when the run time error occurs.
}
catch
{
-statements which requires execution only when the run time error occurs.
}
[--< multiple catch blocks if required >--]

Add a class Exception demo.cs and write the following code:


using System;

namespace CSharpConsole
{
    class ExceptionDemo
    {
        static void Main()
        {
            int x, y, z;
            try
            {
                Console.WriteLine("Enter x value: ");
                x = int.Parse(Console.ReadLine());

                Console.WriteLine("Enter y value: ");
                y = int.Parse(Console.ReadLine());

                z = x / y;
                Console.WriteLine(z);
            }
            catch (DivideByZeroException ex1) //ex1 is a variable of class          DivideByZeroException
            {
                Console.WriteLine("Divisor must not be zero");
            }
            catch (FormatException ex2) //ex2 is a variable of class FormatException
            {
                Console.WriteLine("Input must be numeric");
            }

            catch (Exception ex3)
            {
                Console.WriteLine(ex3.Message);//message is a read only property
            }
            {
                Console.WriteLine("End of the program");
                Console.ReadLine();
            }
         }
    }
}

Tuesday 12 March 2013

Types of Delegates

Delegates are of two types:
  • Unicast Delegate
  • Multicast Delegate
If a delegate is used for calling a single method we call it as a unicast delegate whereas if a delegate is use for calling multiple methods its a multicast delegate.
In case of the methods delegate, a single delegate call will execute all the methods that are bound with the delegate.
using System;

namespace CSharpConsole
{
    public  delegate void MathDel(int x, int y);
    class DelMulti
    {
        public void Add(int x, int y)
        {
            Console.WriteLine("Add:  " + (x + y));
        }
        public void Sub(int x, int y)
        {
            Console.WriteLine("Sub:  " + (x - y));
        }
        public void Mul(int x, int y)
        {
            Console.WriteLine("mul:  " + (x * y));
        }
        public void Div(int x, int y)
        {
            Console.WriteLine("Div:  " + (x / y));
        }
        static void Main()
        {
            DelMulti obj = new DelMulti();
            MathDel md=new MathDel (obj.Add );
            md+=obj.Sub ;md +=obj.Mul ;md +=obj.Div ;
            md(100,25);
            Console .WriteLine ();
            md(600,30);
            Console .WriteLine ();
            md -=obj.Mul ;
            md(450,50);
            Console .ReadLine ();
            
        }

    }
}
 

 

Delegates in C#

It is also an user defined type which is used for invoking or calling the methods of a class.

A method that is defined under a class can be called in 2 different ways
  • With the help of object of a class if it is non static or name of a class if it is static.
  • By using the delegate also we can call  the method of a class even if it is static or non static.
Note: Calling the method in the 1st process is different than calling the method in the 2nd process.

Calling a method using a Delegate

       If we want to call a method using a delegate we need to adopt the following process
  • Defining a delegate:   
[<modifiers>] delegate <void/type> <Name> ([<Parameter Definition's>])

The definition of a delegate is similar to a method definition where a method will have body whereas a delegate will not have any body where we use these delegates for calling these methods.

Note: While defining a delegate make sure the I/O parameters of Delegates are same as the I/O parameters of the method we want to call with the help of a delegate.
  • As the delegate is a type, after defining a delegate to consume it we need to create an object of it and while creating the object, the method we want to call using the delegate should be passed as a parameter to the delegates constructor.
  • Now call the delegate by passing the required parameter value so that the method gets executed internally.

Delegate Example


using System;
namespace CSharpConsole
{
    class DelDemo
    {
        public void Add(int x, int y)
        {
            Console.WriteLine(x + y);
        }
        public static string SayHello(string name)
        {
            return "Hello " + name;
        }
        public delegate void AddDel(int a, int b);
        public delegate string SayDel(string name);

        static void Main()
        {
            DelDemo obj = new DelDemo();
            AddDel ad = new AddDel(obj.Add);
            SayDel  sd = new SayDel (DelDemo.SayHello);
            ad(100, 50); ad(234, 434); ad(672, 157);
            Console.WriteLine(sd("AAA"));
            Console.WriteLine(sd("BBB"));
            Console.WriteLine(sd("CCC"));
            Console.ReadLine();
                   
        }
    }
}

Monday 11 March 2013

Indexers in Csharp

These are also use for providing access to the values of the class outside of the class outside of the class like a property but provides access to a value with the specific name but indexers provides access to the value with the object of a class using index positions just like an array.
We define indexers in a class as following:

 Syntax:
[<modifiers>]<type> this [int index or srting name]
{
[get{<statements>}]
[set{<statements>}] 
}

Indexers are defined very much similar to properties but an indexer doesn't have any name. In the place of name we use the 'this' keyword which means we are definning an indexer object of that class starts providing access to the values that are present inside the class, either with the help  of index or name.

Add a class Employee.cs and write the following code:

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

namespace CSharpConsole
{
    class Employee
    {
        int _Empno;
        string _Ename, _Job;
        double _Salary;
        public Employee(int Empno)
        {
            this._Empno = Empno;
            this._Ename = "Leena";
            this._Job = "Developer";
            this._Salary = 5000;
        }
        public object this[int index] // accessing by 'index' 
        {  
            //read/wrtie properties with conditions
            get
            {
                if (index == 0)
                    return _Empno;
                else if (index == 1)
                    return _Ename;
                else if (index == 2)
                    return _Job;
                else if (_Salary == 3)
                    return _Salary;
                return null;
            }
            //read/write properties with conditions
            set
            {
                if (index == 1)
                    _Ename = value.ToString();
                else if (index == 2)
                    _Job = value.ToString();
                else if(index==3)
                    _Salary =(Convert.ToDouble(value));
            }
        }
        public object this[string name]   //accessing by'name'
        {
            get
            {
                if (name == "Empno")
                    return _Empno;
                else if (name == "Ename")
                    return _Ename;
                else if (name == "Job")
                    return _Job;
                else if (name == "Salary")
                    return _Salary;
                return null;
            }
            set
            {
                if (name == "Ename")
                    _Ename = value.ToString();
                else if (name == "Job")
                    _Job = value.ToString();
                else if (name == "Salary")
                    _Salary = Convert.ToDouble(value);

            }
        }
    }
}
Add another class TestEmployee.cs and write the following code:
using System;

namespace CSharpConsole
{
    class TestEmployee
    {
        static void Main()
        {
            Employee emp = new Employee(1001);
            Console.WriteLine(emp[0]);
            Console .WriteLine (emp [1]);
            Console.WriteLine(emp[2]);
            Console.WriteLine(emp[3]);
            
            // Assigning a new value
            emp[1] = "Cheryl";
            emp["Ename"] = "BA";
            emp[3] = 8000;

            Console.WriteLine(emp["Empno"]);
            Console.WriteLine(emp["Ename"]);
            Console.WriteLine(emp["Job"]);
            Console.WriteLine(emp["Salary"]);
            Console.ReadLine();
        }
    }
}

First outing in Hyderabad with friends!!

     Finally, for the 1st time in 2 months we roamed in Hyderabad. I, along with my room mates went to NTR garden on Saturday. Actually we had planned to go to Lumbini Garden but unfortunately it was closed because of the trouble going on in Hyderabad. So then we finally went to NTR, We went around 3 in the afternoon and returned around 8 at night. We thoroughly enjoyed ourselves.
     Now back to the task which sudeep gave us. Sudeep had told me to do some updations such as some validations, to be able to edit, delete and add new courses at runtime etc. I am still working on it and I hope to finish it as soon s possible.

Friday 8 March 2013

Women's Day Special

Today, on Women's Day I got a bunch of Beautiful flower, Chocolate and a Sweet Gift from Inforica. It was a Good Surprise for me when I reached office and saw a bunch of flower, chocolate and a gift already kept on my desk, Thank you so much Sudeep for making every Women feel special today, in Inforica.

Today, I Solved some online Sample papers of IBPS Exam just for practice since I  have applied for that Examination and the exam day is coming closer. Apart from this I am doing the Updations that Sudeep told me to do in my GetJob Project. I am done with adding Master page and linking it with the Content pages so that the Title and Menu Control will appear in each page. Now left with some validation part. Will probably complete today.

Normailization in SQL Server

Normalization is a process of minimizing data redundancy with a series of steps called as normal forms.

The total normalization process includes the following normal forms.
  • First Normal Form (1NF)
  • Second Normal Form (2NF)
  • Third Normal Form (3NF)
  • Boyce Codded Normal Form (BCNF)
  • Fourth Normal Form (4NF)
  • Fifth Normal Form (5NF)
  • Restrict Union Normal Form (RUNF)
  • Project Join Normal Form (PJNF)
  • Sixth Normal Form (6NF)
First Normal Form (1NF):  A table is said to be in 1NF if and only if a primary key is defined for that table and the table does not contain any multivalued columns.

Second Normal Form (2NF): A table is said to be in 2NF if and only if the table is in 1NF and no partial dependencies exist in the table.

Third Normal Form (3NF): A table is said to be in 3NF if and only if the table is in 2NF and no transient dependencies exist in the table.



Thursday 7 March 2013

Properties

There are also members of a class using which we can provide access to the value of a class outside of the class.
If at all a class is associated with any values and if we want those values to be accessible outside of the class we can provide access to those values in two different ways.
  • By storing value under a public variable we can provide access to that value outside the class but in this case the public variable gives get value or set the value.
       public class Test
       {
       public int x=100;
       }
       Test obj=new Test()
       int a=obj x
       obj.x=100
  • By storing the value under a private value also of a class by defining a property on that variable given in three different ways
  1. Both get and set access(Read/write/property)
  2. Only get access(Read only property)
  3. Only set access(write only property)
Syntax to define a property:

      [<modifiers>]<type>[Names]
      {
      [get{statements}]  // Get accessor
      [set{statements}]  // Set accessor
      }


Wednesday 6 March 2013

Methods of a 'class' in CSharp

A class is a collection of members, where members of class can be off various kinds like :
  • Fields
  • Members
  • Constructors
  • Destructors
  • Properties
  • Indexes
  • Events
  • Delegates
  • Enum
Destructor: This is also a special method present under a child class same like a constructor but constructor method gets called when object of class is created and destructor is called whenobject of class is destroyed.
   Both constructor and destructor method will exactly have the same name i.e the name of the class which they have. To differentiate between this two we use 'tidle' operation before the destructor method.

class Test
 {
    Test() 
     {
        //Constructors
     } 
   ~Test()
    {
      //Destructors
    }
}
  • Destructor methods cannot be applied with any modifirs or parameters.
  • Garbage Collector is responsible for destroying the object of class and when the object of class is being destroyed, destructor methods gets called and moreover Garbage Collector can destroy the object of class in any of the following three classes.
  1. In the end of a program's execution each and every object i.e associated with the program is automatically destroyed.
  2. Sometime in the middle of a programs execution implicit calling of Garbage Collector takes place provided the memory is full that it identifies finds unused object and destroys them.



Tuesday 5 March 2013

Exception Handling In SQL Server

Similar to other programming languages SQL server also supports exception handling i.e handles the exceptions, provide a proper message to the user regarding exception and avoid abnormal termination of the program.
Up to SQL sever 2000, a system variable called @@Error is use to get information about the exception and handle the exception but from SQL Server 2005 onwards exception handling is done by using try catch.

Within SQL server,  a try block can have only one catch block.
Syntax:
         begin try
          <statements>
         end try
          begin catch
          <statements>
         end catch

Error Functions
To get information about raised exception a set of functions are provided, which are collectively called as Error Functions are new in SQL 2005.
  • Error_Number() : Returns the unique number of raised error.
  • Error_Message() : Returns the message associated with the current  error raised.
  • Error_Severity() : Returns the severity of the current error raised.
  • Error_State() : Returns the state of current error raised.
  • Error_Procedure() : Returns name of the procedure in which exception occurs.
  • Error_Line() : Returns the line number within the procedure where error occurs.
Geting List of SQL Server error messages:
select * from sys.messages

You can add your own error messages to the error messages list of SQL server using the stored procedure sp_add message.

Raising Errors Manually:
There are situations where system will not raise an exception for your requirement and you want to raise exception manually for this use the riase error function that has following syntax :

raiserror(msgid/msgtext,severity,state[,arguments])

Triggers

      Triggers are stored sub-programs that will be automatically executed based on specified event.

Differences between Stored Procedures, User Defined Functions and Triggers are as follows-->
  • Stored Procedures and User Defined Functions can be called by the user manually but triggers cannot be called by the user manually and they will be automatically invoked.
  • Stored Procedures can return a value with output parameters and User Defined Functions can return a value with return statement but triggers cannot return a value either with output parameters or return statement.
  • Stored Procedures, User Defined Functions can take arguments but triggers cannot take arguments.
Based on event specified on a trigger, triggers are classified into DDL triggers and DML triggers. When the trigger is created by specifying a DDL command as event then that trigger is called as DDL triggers and when a trigger is created by specifying a DML command then that trigger is called as DML triggers. 
     
      DDL triggers are new in SQL 2005. DML triggers have the following three purposes-->
  • Create procedure integrity constraints.
  • Record auditing information of a table.
  • Allow insert,update,delete on complex views.

Access Modifiers

Members that are defined in type by any scope on specific are always accessible within the type. Restrictions comes into picture only when we try to access them outside of the type. Members declared as private under a class or structure cant be access outside of the type in which they are defined and moreover there default scope is private only.

Types cant be declare as private so private can be use only on members. One point to keep in mind is that Interface cant contain any members and default scope for interface members is public.
  • Protected: Members declared as protected under a class be accessed only within the class or in a child class.Non child classes cant consume them. Types cant be declared as protected also, so this can only be used on members.
  • Internal: Members and types that are declared as internal can be consumed only within the project bot both from child or non child. The default scope for any type in C# is internal only.
  • Protected Internal: Members declared as protected will have dual scope i.e within the project they behave as internal providing access to anywhere in project outside the classes they will change to protected and still provide access to their child classes. Types cannot be declared as protected internal also. So this can also be used only on members.
  • Public: A type or member of a type if declared as public is global in scope which can be accessed from anywhere.

Monday 4 March 2013

Stored sub programs in SQL

  • Stored subprograms are the programs that are permanently stored in the database. Execution of stored sub-programs will be fast compare to independent SQL statements.
  • Hence to perform any operation again database from the front end application like .Net it is recommended to use stored sub programs than independent SQL statements to improve the performance of application.
  •   Before executing an independent SQL statements , SQL server has to perform parsing execution plan generation and cost estimation. During Parsing it will verify syntax of statement, availability of object refers in the statement, permissions of current user to perform specified operations on specified object and data type compatibility. As all this steps takes time execution will be slow and it affects performance of application.
  • Stored procedures are classified into :
  • Stored procedures
  • User defined procedures
  • Triggers
Stored Procedure: Stored procedures are the stored subprograms that cannot return a value with return statement. A stored procedure can contain return statemnet without a value to return and purpose of this is to exit from stored procedure.

 Syntax:
create procedure<procname>[(<parameters>)]
[with encryption] as begin
<statements>
end

User-defined functions in SQL

User defined functions are stored subprograms that must return a value with return statements. User defined functions are classified functions.
  • Scalar function: This are the user defined functions that return a single value. 

  • Valued functions: This are user defined functions that returns a table.  Table valued functions are classified into inline table valued functions and multistatement table values statement.
  • Inline Table valued functions:This are the table valued functions that contain a single statement i.e the return statement with a select statement within it, whose results will be converted inline as a table.
Inline table valued function must not contain the keyword begin and end.
  • Multistatement valued functions: This are table value functions that contain multiple statements. In case of multistatemnet table values function you have to create a table in a function manual, insert rows into it and return it manual.

Sunday 3 March 2013

Working with ASP

Sudeep had given us the task of creating an aspx page and connecting it to the database. I successfully managed to create my first aspx page within a day.. Then after i showed it to Sudeep he asked us to do some updations like putting validations,adding links of editing and deleting etc. I even completed that within a day too. Then after i showed that also to him he made it more challenging for me by asking me to add Menus. Now i am still working on it. Now its becoming more and more challenging for me and i am enjoying  working with challenges.