Thursday, 13 October 2016

C# Tutorial Part 2

Class
Class are template of an object .It contain data , method , function to make the object usable .For example , we create an object “student” , student have some property , like student name ,date of birth ,roll number ect .More over student have an property also called  parent name . Then how we should describe “student” object or class ?


class student
{
    string student_name;
    DateTime date_of_birth;
    int roll_number;
    string parent_name;
}


Now , the student class properly describe the student .But class also contain method, function for specific work. These are called member of the class.
class student
{
    string student_name;
    DateTime date_of_birth;
    int roll_number;
    string parent_name;
    string parent_name;
    void calculate_age()
    {
    }
}

Now, student_name , date_of_birth, roll_number,parent_name, calculate_age all are member of the class .How we will go some other property of the class. One property is nested type. That means one class have been nested under another class . We have already declared how to declare class and we have declare the class “student” . Now we will declare the “student” class under a class called “school”.

class school
{
    string name_of_school;
    string address_of_school;

    class student
    {
        string student_name;
        DateTime date_of_birth;
        int roll_number;
        string parent_name;
        string parent_name;
        void calculate_age()
        {
        }
    }
}


Now , the next comes , how to use class ?.To use an class we need to create instance of the class .Each class has an constructor , we need to initialized the constructor. For Example
student obj = new student();

To understand the concept , we need some modification of the class , just declare public , we will get all the property of the object instance.
public class student
{
    public string student_name;
    public DateTime date_of_birth;
    public int roll_number;
    public string parent_name;
    public string parent_name;
    public void calculate_age()
    {
    }
}

student obj = new student();

But why I had declare public class and member public ? There is a discussion scope and access level. Generally there are three type of access modifier private , public , protected.Other than this , other are friend and protected friend.Now let us see the role of access modifier.
Public : Can be access from any where.
Private : Can be access by the member of the same class only.
Protected : can be acess by the member of the same class only and inherited from base class.
Friend: Can be access from , within the assembly.
Example :

public class student
{
     string student_name;
     DateTime date_of_birth;
     int roll_number;
     string parent_name;
     string parent_name;
     void calculate_age()
    {
    }
}
 private class student
{
     string student_name;
     DateTime date_of_birth;
     int roll_number;
     string parent_name;
     string parent_name;
     void calculate_age()
    {
    }
}


protected class student
{
     string student_name;
     DateTime date_of_birth;
     int roll_number;
     string parent_name;
     string parent_name;
     void calculate_age()
    {
    }
}

Inheritance
Inheritance is the feature of the .Net framework , which allow to create a new class with all the member of previously defined class .For example ,we have defined class A ,, now inherited class B . All member of class A will come to Clasas B automatically.The first class is called Base class an second class is called derived class . In other object oriented programming language allow unlimited level of inheritance  , but .Net frame work allow only 2nd level inheritance . The main advantage of inheritance is just copy/implement common functionality of Base class to derived clasas . Now I am creating an class
 

public class parent //base class
{
    public int public_member;
    public int public_method(int a, int b)
    {
        return (a + b);
    }
}

public class child : parent
{
    //derived class
}

Notice that , child class do not have any method .Now I am creating instance of the clind class.
        child obj = new child();

obj.public_member;
obj.public_method();
We get both member of the parent class in child class . Noticed that , member of the parent class declared public ,so that we can inherit it , only public , protected access modifier will be available during Inheritance .Here is an example ,

public class Parent
{
    private void Method1()
    {
    }
    protected void Method2()
    {
    }

}

public class child : Parent
{
    public void method_call()
    {
        this.method1();//compliler through error-inacccable due to protection level
        this.Method2.method2();//will compile & work
    }
}

Is there any way , that we can define a class that can not be Inherited ?
Yes . there is , the keyword called “sealed” , seal keyword tells compiler that , this class can not be inherted  . For example
public sealed class  Myclass
{

}
Now , I am trying to Inherit the clasas “MyClasas”
public class MyChild : Myclass
{
}
//error MyChild': cannot derive from sealed type 'Myclass'

An error will shown , sealed class can not be inherited , but we can create instance of the seal class .The question is , what is the use of sealed class ?
Sealed class is mainly used for security features, so that class cannot be modified.



013 Weekend Tour Dooars,Sultanikhola,SamSing,Sultanekhola

Sultanikhola or SamSing is a small village in the state of West Bengal and the in the district of Darjelling. Being less population and lush of green all around the village has made Sultanikhola a good attraction for tourist .Most of the villagers are Nepali and some are Bhitia . The altitude of the place is 650 to 950 meter .








The place is named after a small stream Suntaley Khola.The best place to stay here is West Bengal forest development corporation guest house , other than that , there are number of home stay , you can contact them before going there .To reach Sultanikhola , you have to reach Siliguri or New Jalpaiguri or you can came from  New Mal Junction also.This place is 85 km from Siliguri and 34 km from New Mal junction . During the travel towards to Sultanikhola , you will see green tea garden all around the road , some place are covered with dense forest . This place is also popular for trekking.










There we found two place for sight seeing, Rocky Island and Lali Gorus .Both place are a few kilometer away .A small stream is coming downwards and several well shaped rock and finally a bridge to cross the stream.The place is like a picture , sound of water , silence of Forest all around create a scenic beauty for this place . The next place “Lali Gorus” , as our driver told us .This place is a valley ,there is a view point also ,or you can get down to the valley by walking , there is a small road . You will notice green hills all around you ,gentle breeze , a small stream is going through , tourist are getting into the stream and taking picture , you may spend few hour here .Please note that we could not connect any internet connection or could not get any mobile tower here .






To reach WBFDC guest house , you need to cross a small hanging bridge , children enjoy the bridge as it vibrate while you walk through it .In the morning you will getup with the creeping of some unknown bird , the place is full of several king of bird  and also Butterfly .In the guest house , you will see a variety color of butterfly all around you.

Tuesday, 4 October 2016

Differences between Sql server 2005, 2008, 2008r2, 2012

MS SQL Server 2005
  • Exception Handling was introduces.
  • Varchar(Max) data type introduces.
  • Bulk Copy Update introduces.
  • Previous version of Sql server was in two part ,enterprise manager and query analyzer ,both are combined as SQL Server management Studio (SSMS).
 MS SQL Server 2008
  •  Encrypt the entire database introduced in 2008.
  •  XML datatype is used.
  •  Date and time are separately used for date and time datatype.
  •  Table datatype introduced.
  •  Central Management Server (CMS) was introduced.
  •  Filestream is introduced
  •  Merge Statement  introduced.
SQL Server 2008 R2
  •   PowerPivot for SharePoint,
  •   PowerPivot for Excel,
  •   Multi-Server Administration introduced .

SQL Server 20012
  •  Exceptions handling with THROW option introduced .
  • The BCP Utility and SQLCMD Utility utilities enhanced with -K option, which allows to specify read-only access to a secondary replica in an AlwaysOn availability group.
  • ORDER BY Clause have OFFSET / FETCH options introduced for paging .
  • TRY_CONVERT() and FORMAT() introduced .
  • SQL server 2012 has unlimited concurrent connections.

@@IDENTITY & SCOPE_IDENTITY & IDENT_CURRENT

 
@@IDENTITY : Fethch the last identity value of any current session.After insert , insert into , bulk insert , identity value is generated.If insertion sucessfully effect then , @@IDENTITY return the last value , if insertion do not effect then @@IDENTITY return null .Please remember that @@IDENTITY have to put immediately after the insertion statement.

CREATE TABLE student
(
id int identity,
student_name varchar(500)
)
 
We have just created table , not insertde data , I am executing @@IDENTITY
SELECT @@IDENTITY
it will retun --NULL

Now i am inserting data
INSERT INTO student(student_name)
SELECT 'student1'
UNION
SELECT  'student2'
Now i am executing the command
SELECT @@IDENTITY

it will retun --2, the last identity value

Now sometimes we need to reset the identity identity column.
we can simple run truncate statement to reset identity column.

TRUNCATE TABLE student
It will reset their column from the first
Another way is
DBCC CHECKIDENT('student', RESEED, 0)

The DBCC (Database Console Commands) command will reset the identity 


SCOPE_IDENTITY : Fetch the last identity value by current scope.There can be several type of Scope ,procedure , trigger , batch statement.To test the information i am creating a procedure , which insert value to student

CREATE PROCEDURE sp_student
(
  @return_id int out
)
AS
BEGIN
   INSERT INTO student(student_name)
   SELECT  'student1'
   UNION
   SELECT 'student2'
SET @return_id = scope_Identity()
END

Now i am executing the procedure
DECLARE @id INT
EXEC sp_student  @id output
SELECT @id
Procedure retuns-2

 

IDENT_CURRENT--Fetch the last identity value of a table.It can be of any session or any scope.For example if i insert from scope A , then from Scope B.
IDENT_CURRENT will return the last value inserted from Scope B
In above example i have created a procedure named 'sp_student' , i am calling again and inserting some manual data.

--Step 1  (2 data inserted)          
DECLARE @id INT
EXEC sp_student  @id OUTPUT
SELECT @id
--Step 2  (2 data inserted)
INSERT INTO student(student_name)
SELECT 'student3'
UNION
SELECT 'student4'
--Now ,if we run
SELECT IDENT_CURRENT('student')
result is 8

Monday, 3 October 2016

Changing the image source using jQuery


Changing the image source using jQuery

<img  height="15" width="15" id="btnSaveUnsave" />
<script>
    $(document).ready(function () {
        $('#btnSaveUnsave').attr('src', '../../Images/cross.png');       
    });

</script>

C# Namespaces


Namespaces
Namespaces are a logical grouping , it is not connected with physical file or code ect. Namespaces are generally  structured as hierarchies to use & reuse of names in different contexts . In Microsoft .Net ,a namespace is an abstract container providing context for the items . When we write  program , it is created  with a default namespace. This default namespace is called as global namespace. But the program has capability of declare any number of namespaces in it also , but it should be  a unique name. The result  is that every namespace can contain any number of classes, functions, variables and also namespaces etc., whose names are unique only inside the namespace. 

In C# , we can define

namespace namespace_name
{
    // code
}

For example I am writing names space student , and declaring object in it

namespace student
{
   class student_info
   {
     name string;  
     roll int;    
   }
}

Now I , can create instance of class “student_info” ,like  


student.student_info sc = new student. student_info();

We can use “using” keyword also to access the namespace. This statement tells the compiler that the subsequent code is making use of names in the that namespace.For example I am creating a namespace “class” and a class of name “class_info”


namespace class
{
   class class_info
   {
     class_name string;  
     no_of_student  int;
     class_teacher_name string;  
   }
}
 Now at the top , we should write 

using System;
using classes;
Now class under namespace “classes” , will be easily available .We ca use


class_info c1=new class_info();

 Namespace hierarchy
Namespaces allow you to create a systematic organized code via hierarchical system.
A good code should put the general name at the top of the hierarchy and more specific
As get down.
For example “System” is the highest level of  namespace hierarchy, “using System” will allow you some general coding , standard library etc.
System.Data, System.Net comes under “System” names space .” System.Data” will allow you to access data adopter, dataset,data reader ect. ” System.Net” for some netword component.Please see the below example


namespace Level1Hierchy
{
    class MyClass1
    {
        //defination of the class
    }
    namespace Level2Hierchy
    {
        // Program start class
        class MyClass2
        {
             //defination of the class
        }
    }
}

“Level1Hierchy” is the top level namespace , “Level2Hierchy” is under Level1Hierchy.
“MyClass2” is defined under “Level2Hierchy” , we need to write code to access
Level1Hierchy.Level2Hierchy.MyClass2 obj1 = new Level1Hierchy.Level2Hierchy.MyClass2();

But “MyClass1” is defined under “Level1Hierchy” , we can access by
Level1Hierchy.MyClass1 obj2 = new Level1Hierchy.MyClass1();

How to see temp table created by code in sql server?


How to see temp table created by code in sql serve ?
create table #temp
(
id int
)

SELECT  * FROM tempdb.dbo.sysobjects O
WHERE O.xtype in ('U')
AND O.ID = OBJECT_ID(N'tempdb..#temp')

Name       id
#temp_..         -1503307154

Microsoft SQL Server System Database

Microsoft SQL Server System Database

When we install SQL Server and open Management Studio , we notice that there are four  database comes automatically , master ,model, msdb , tempdb in Database /System Database itself.

How to get list of database from SQL Server?
select * from sys.databases
Result 
master
tempdb
model
msdb
sudent


A) master :The database hold all system level information . Also record all database present in the instance .For example, if we ass add "Student" database , master database will record the information .It also contain initialization information od SQL server.If the database is corrupted , Sql server create problem , There are several method to retrieve the master database. The physical file name of master database is master.mdf  . Newer version of SQL Server system level information have been moved to resource database.

B)model :It is a template of all database .For example , if we created "student" database .The structure will be copied from model . Another good example is , when we start SQl Server  tempdb is created .It also copied from the template of model . Sql Server make sure that model database must contain, before instance of sql server created . As an example , when we run "Create Database"  command ,
first entire structure of model database tables , function , stored procedures will be copied to the new dababase from model then rest work progress .The initial size of model database is 8Mb , physical file model.mdf .Database owner "sa", you cannot change it .you cannot drop or rename it.

C)msdb : msdb is responsible for all joining and maintenance plan and DTS pakage.It is also responsible for backup history .Database mail , Sql Server agent also maintain by msdb .Jobs ,log shipping is also msdb responsibility .It also hold information of which database backup was last taken .Physical file name of MSDGData.mdf , also responsible for simple recovery model.

D) tempdb : tempdb has an huge work. When we create a temptable , it actually create on tempdb.
When we use table variable , function return table, it also create on tempdb. It is also , responsible for pasring query , cursor, trigger and also user define function .Internal object created by Sql Server also hold by tempdb.Sql server transaction management is done with the help of tempdb. Commit, rollback.

How to see temp table created by code in sql server?

create table #temp
(
id int
)

SELECT  * FROM tempdb.dbo.sysobjects O
WHERE O.xtype in ('U')
AND O.ID = OBJECT_ID(N'tempdb..#temp')

Name       id
#temp_..         -1503307154

বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...