Thursday, 25 June 2015

Use of ? in C#

You might be using ? in your code many times but when it gets specifically asked what is the use of ?
in C# then sometimes you not able to recall which makes this as an interview question.
Coming to the answer. Below are soem usage of "?" in C#

Nullable type :
To declare a nullable type ? is gets used.
e.g.
    int? num = null;

Nullable types are instances of the System.Nullable<T> struct. A nullable type can represent the correct
range of values for its underlying value type, plus an additional null value.

?? Operator (null-coalescing operator) which returns the left-hand operand if the operand is not null;
otherwise it returns the right hand operand. It mostly gets used with nullable types.   
int? x = null;
int y = x ?? -1;

In above example if x is null then y will have -1 value else x's value.

Conditional operator (?:)
? gets used in conditional operator which returns one of two values depending on the value of a Boolean expression.
   
int i = 6;
string str = (i >3 ? "yes": "no");

In above example conditional operator is used. So if i > 3 condition is true str will have value "yes" else value "no"

What is difference of int and uint?

Both int and uint are 32 bit integral types the difference is int is signed integral and uint is a unsigned integral i.e. int can have both negative and postive integral values but uint always has positive values in a range of 0 to 4,294,967,295.

Wednesday, 24 June 2015

Case Sensitive search with SQL

If we fire following Query,
"select * from users where name = 'raja'"
it will return us all columns. Cause, all column contains same data and record search is not case Sensitive.

Default Collation of the SQL Server installation SQL_Latin1_General_CP1_CI_AS and this is not case sensitive. here is syntax to change column collation. 

 If we fire following Query,
"select * from users where name COLLATE Latin1_General_CS_AS = 'raja'"
it will return  record search is case Sensitive.

Tuesday, 23 June 2015

Implement Mutually Exclusive CheckBoxList (CheckBoxes) inside GridView in ASP.Net

Mutually exclusive CheckBoxList means when one CheckBox is checked, all other CheckBoxes present in the CheckBoxList will be unchecked.

 HTML Markup
The following HTML Markup consists of a GridView with two BoundField columns and a TemplateField column containing an ASP.Net CheckBoxList control.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound = "OnRowDataBound">
    <Columns>
        <asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
        <asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="100" />
        <asp:TemplateField HeaderText="Gender" ItemStyle-Width="150">
            <ItemTemplate>
                <asp:CheckBoxList ID = "chkGender" runat="server" RepeatDirection = "Horizontal">
                    <asp:ListItem Text="Male" Value="M" />
                    <asp:ListItem Text="Female" Value="F" />
                </asp:CheckBoxList>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>


protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        DataTable dt = new DataTable();
        dt.Columns.AddRange(new DataColumn[4] { new DataColumn("Id"), new DataColumn("Gender"), new DataColumn("Name"), new DataColumn("Country") });
        dt.Rows.Add(1, "M", "Sujoy Santra", "India");
        dt.Rows.Add(2, "M", "Sumit Kumar Sen", "Brazil");
        dt.Rows.Add(3, "F", "Soumi Santra", "India");
        dt.Rows.Add(4, "M", "Mithun Patra", "Canada");
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
}







 Populating the Selected Value of CheckBoxList in GridView
Inside the OnRowDataBound event handler of GridView, first the value of Gender is determined from the DataItem object of the GridView.
Finally the CheckBoxList is referenced using the FindControl method and its selected value is set.
C#
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        string gender = (e.Row.DataItem as DataRowView)["Gender"].ToString();
        CheckBoxList chkGender = (e.Row.FindControl("chkGender") as CheckBoxList);
        chkGender.Items.FindByValue(gender).Selected = true;
    }
}

 Implement Mutually Exclusive CheckBoxList (CheckBoxes) inside GridView
Inside the jQuery document ready event handler, a click event handler is assigned to each CheckBox of all the CheckBoxLists present inside the GridView.
When a CheckBox is clicked in a CheckBoxList, all the CheckBoxes except the current are unchecked.
<script type="text/javascript" src="script/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("[id*=chkGender] input").click(function () {
            $(this).closest("table").find("input").not(this).removeAttr("checked");
        });
    });
</script>

Wednesday, 17 June 2015

Difference between class and instance variables

 Now, it should be clear what the difference between instance and class variables is. Class variables only have one copy that is shared by all the different objects of a class, whereas every object has it’s own personal copy of an instance variable. So, instance variables across different objects can have different values whereas class variables across different objects can have only one value.

Tuesday, 16 June 2015

what is the difference between the right and left outer joins?

 The difference is simple – in a left outer join, all of the rows from the “left” table will be displayed, regardless of whether there are any matching columns in the “right” table. In a right outer join, all of the rows from the “right” table will be displayed, regardless of whether there are any matching columns in the “left” table.

In SQL, what’s the difference between a full join and an inner join?


Let’s start with a quick explanation of a join. Joins are used to combine
the data from two tables, with the result being a new, temporary table.
The temporary table is created based on column(s) that the two tables share,
which represent meaningful column(s) of comparison. The goal is to extract
meaningful data from the resulting temporary table. Joins are performed based
on something called a predicate, which specifies the condition to use in order
to perform a join.

It is best to illustrate the differences between full joins and inner joins
by use of an example. Here we have 2 tables that we will use for our example:

Employee_EmpID              Location_EmpName
13                                       Sujoy
8                                         Sumit
3                                         Ram
17                                       Babu
25                                      Johnson
   
EmpID     EmpLoc
13             Kolkata, India
8               Delhi,India
3               Pune, India
17             Chennai, India
39             Bangalore, India

For the purpose of our example, it is important to note that the very last
employee in the Employee table (Johson, who has an ID of 25) is not in the
Location table. Also, no one from the Employee table is from Bangalore
(the employee with ID 39 is not in the Employee table). These facts will be
significant in the discussion that follows.
Full joins

Let’s start the explanation with full joins. Here is what the SQL for a full
join would look like, using the tables above:

select * from employee full join location
on employee.empID = location.empID;

Subscribe to our newsletter on the left to receive more free interview questions!

A full join will return all rows that match based on the “employee.empID = location.empID”
join predicate, and it will even return all the rows that do not match – which is why
it is called a full join. The SQL above will give us the result set shown below:

Employee.EmpID     Employee.EmpName     Location.EmpID     Location.EmpLoc
13                                  Sujoy                          13                            Kolkata,India
8                                    Sumit                          8                              Delhi,India
3                                    Ram                            3                              Pune, India
17                                  Babu                           17                            Chennai, India
25                                 Johnson                        NULL                    NULL
NULL                           NULL                         39                           Bangalore, India

You can see in the table above that the full outer join returned all the rows from
both the tables – and if the tables do have a match on the empID, then that is made
clear in the results. Anywhere there was not a match on the empID, there is a “NULL”
for the column value. So, that is what a full join will look like.
A full join is also known as a full outer join

It’s good to remember that a full join is also known as a full outer join – because
it combines the features of both a left outer join and a right outer join .


What about inner joins?

Now that we’ve gone over full joins, we can contrast those with the inner join. The
difference between an inner join and a full join is that an inner join will return
only the rows that actually match based on the join predicate – which in this case
is “employee.empID = location.empID”. Once again, this is best illustrated via an
example. Here’s what the SQL for an inner join will look like:

select * from employee inner join location on
employee.empID = location.empID

This can also be written as:

select * from employee, location
where employee.empID = location.empID
             

Now, here is what the result of running that SQL would look like:
Employee.EmpID     Employee.EmpName     Location.EmpID     Location.EmpLoc
13                             Sujoy                               13                           Kolkata,India
8                               Sumit                               8                             Delhi,India
3                               Ram                                 3                             Pune, India
17                            Babu                                17                            Chennai, India
The difference between the full join and inner join

We can see that an inner join will only return rows in which there is a match based
on the join predicate. In this case, what that means is anytime the Employee and
Location table share an Employee ID, a row will be generated in the results to show
the match. Looking at the original tables, one can see that those Employee ID’s that
are shared by those tables are displayed in the results. But, with a full join, the
result set will retain all of the rows from both of the tables.

What is the difference between a Clustered and Non Clustered Index?

A clustered index determines the order in which the rows of a table are
stored on disk. If a table has a clustered index, then the rows of that
table will be stored on disk in the same exact order as the clustered index.
An example will help clarify what we mean by that.

An example of a clustered index

Suppose we have a table named Employee which has a column named EmployeeID.
Let’s say we create a clustered index on the EmployeeID column. What happens
when we create this clustered index? Well, all of the rows inside the Employee
table will be physically – sorted (on the actual disk) – by the values inside
the EmployeeID column. What does this accomplish? Well, it means that whenever
a lookup/search for a sequence of EmployeeID’s is done using that clustered index,
then the lookup will be much faster because of the fact that the sequence of
employee ID’s are physically stored right next to each other on disk – that is
the advantage with the clustered index. This is because the rows in the table
are sorted in the exact same order as the clustered index, and the actual table
data is stored in the leaf nodes of the clustered index.

Remember that an index is usually a tree data structure – and leaf nodes are the
nodes that are at the very bottom of that tree. In other words, a clustered index
basically contains the actual table level data in the index itself. This is very
different from most other types of indexes as you can read about below.
When would using a clustered index make sense?

Let’s go through an example of when and why using a clustered index would actually
make sense. Suppose we have a table named Owners and a table named Cars. This is
what the simple schema would look like – with the column names in each table:

Owners
Owner_Name
Owner_Age

Cars
Car_Type
Owner_Name

Let’s assume that a given owner can have multiple cars – so a single Owner_Name
can appear multiple times in the Cars table.
Now, let’s say that we create a clustered index on the Owner_Name column in the Cars
table. What does this accomplish for us? Well, because a clustered index is stored
physically on the disk in the same order as the index, it would mean that a given
Owner_Name would have all his/her car entries stored right next to each other on disk.
In other words, if there is an owner named “Joe Smith” or “Raj Gupta”, then each owner
would have all of his/her entries in the Cars table stored right next to each other
on the disk.

When is using a clustered index an advantage?

What is the advantage of this? Well, suppose that there is a frequently run query
which tries to find all of the cars belonging to a specific owner. With the
clustered index, since all of the car entries belonging to a single owner would
be right next to each other on disk, the query will run much faster than if the
rows were being stored in some random order on the disk. And that is the key
point to remember!

Why is it called a clustered index?

In our example, all of the car entries belonging to a single owner would be right
next to each other on disk. This is the “clustering”, or grouping of similar values,
which is referred to in the term “clustered” index.

Note that having an index on the Owner_Name would not necessarily be unique, because
there are many people who share the same name. So, you might have to add another
column to the clustered index to make sure that it’s unique.
What is a disadvantage to using a clustered index?

A disadvantage to using a clustered index is the fact that if a given row has a value
updated in one of it’s (clustered) indexed columns what typically happens is that the
database will have to move the entire row so that the table will continue to be sorted
in the same order as the clustered index column. Consider our example above to clarify
this. Suppose that someone named “Rafael Nadal” buys a car – let’s say it’s a Porsche –
from “Roger Federer”. Remember that our clustered index is created on the Owner_Name column.
This means that when we do a update to change the name on that row in the Cars table,
the Owner_Name will be changed from “Rajendra” to “Rajkumar”.

But, since a clustered index also tells the database in which order to physically store
the rows on disk, when the Owner_Name is changed it will have to move an updated row
so that it is still in the correct sorted order. So, now the row that used to belong to
“Roger Federer” will have to be moved on disk so that it’s grouped (or clustered) with all
the car entries that belong to “Rafael Nadal”. Clearly, this is a performance hit.
This means that a simple UPDATE has turned into a DELETE and then an INSERT – just
to maintain the order of the clustered index. For this exact reason, clustered indexes
are usually created on primary keys or foreign keys, because of the fact that those
values are less likely to change once they are already a part of a table.

A comparison of a non-clustered index with a clustered index with an example

As an example of a non-clustered index, let’s say that we have a non-clustered index
on the EmployeeID column. A non-clustered index will store both the value of the EmployeeID
AND a pointer to the row in the Employee table where that value is actually stored. But a
clustered index, on the other hand, will actually store the row data for a particular
EmployeeID – so if you are running a query that looks for an EmployeeID of 15, the data
from other columns in the table like EmployeeName, EmployeeAddress, etc. will all
actually be stored in the leaf node of the clustered index itself.

This means that with a non-clustered index extra work is required to follow that pointer
to the row in the table to retrieve any other desired values, as opposed to a clustered
index which can just access the row directly since it is being stored in the same order
as the clustered index itself. So, reading from a clustered index is generally faster
than reading from a non-clustered index.
A table can have multiple non-clustered indexes

A table can have multiple non-clustered indexes because they don’t affect the order
in which the rows are stored on disk like clustered indexes.
Why can a table have only one clustered index?

Because a clustered index determines the order in which the rows will be stored on disk,
having more than one clustered index on one table is impossible. Imagine if we have two
clustered indexes on a single table – which index would determine the order in which the
rows will be stored? Since the rows of a table can only be sorted to follow just one index,
having more than one clustered index is not allowed.
Summary of the differences between clustered and non-clustered indexes

Here’s a summary of the differences:

    A clustered index determines the order in which the rows of the table will be stored
on disk – and it actually stores row level data in the leaf nodes of the index itself.
A non-clustered index has no effect on which the order of the rows will be stored.
    Using a clustered index is an advantage when groups of data that can be clustered
are frequently accessed by some queries. This speeds up retrieval because the data lives
close to each other on disk. Also, if data is accessed in the same order as the
clustered index, the retrieval will be much faster because the physical data stored
on disk is sorted in the same order as the index.
    A clustered index can be a disadvantage because any time a change is made to a
value of an indexed column, the subsequent possibility of re-sorting rows to maintain
order is a definite performance hit.
    A table can have multiple non-clustered indexes. But, a table can have
only one clustered index.
    Non clustered indexes store both a value and a pointer to the actual row
that holds that value. Clustered indexes don’t need to store a pointer to the
actual row because of the fact that the rows in the table are stored on disk
in the same exact order as the clustered index – and the clustered index actually
stores the row-level data in it’s leaf nodes.



In SQL, what’s the difference between the having clause and the where clause?

Difference between having and where clause

So we can see that the difference between the having and where clause in sql is
that the where clause can not be used with aggregates, but the having clause can.
One way to think of it is that the having clause is an additional filter to the
where clause.

The difference between the having and where clause is best illustrated by an example.
Suppose we have a table called emp_bonus as shown below. Note that the table has multiple
entries for employees A and B.
emp_bonus

Employee     Bonus
A                 1000
B                 2000
A                500
C                700
B                1250

If we want to calculate the total bonus that each employee received, then we would
write a SQL statement like this:

select employee, sum(bonus) from emp_bonus group by employee;

The Group By Clause

In the SQL statement above, you can see that we use the "group by" clause with the
employee column. What the group by clause does is allow us to find the sum of the bonuses
for each employee. Using the ‘group by’ in combination with the ‘sum(bonus)’ statement will
give us the sum of all the bonuses for employees A, B, and C.


Running the SQL above would return this:
Employee     Sum(Bonus)
A                  1500
B                  3250
C                  700

Now, suppose we wanted to find the employees who received more than 1,000 in bonuses
for the year of 2007. You might think that we could write a query like this:

BAD SQL:
select employee, sum(bonus) from emp_bonus
group by employee where sum(bonus) > 1000;

The WHERE clause does not work with aggregates like SUM

The SQL above will not work, because the where clause doesn’t work with aggregates – like sum,
avg, max, etc.. Instead, what we will need to use is the having clause. The having clause was
added to sql just so we could compare aggregates to other values – just how the ‘where’ clause
can be used with non-aggregates. Now, the correct sql will look like this:

GOOD SQL:
select employee, sum(bonus) from emp_bonus
group by employee having sum(bonus) > 1000;

What’s referential integrity?

Referential integrity is a database concept that ensures that relationships between tables remain consistent.When one table has a foreign key to another table, the concept of referential integrity states that you may not add a record to the table that contains the foreign key unless there is a corresponding record in the linked table. It also includes the techniques known as cascading update and cascading delete, which ensure that changes made to the linked table are reflected in the primary table

SQL Server: Natural Key Verses Surrogate Key

When you design tables with SQL Server, a table typically has a column or a number of columns that are known as the primary key. The primary key is a unique value that identifies each record.  Sometimes the primary key is made up of real data and these are normally referred to as natural keys, while other times the key is generated when a new record is inserted into a table.   When a primary key is generated at runtime, it is called a surrogate key.   A surrogate key is typically a numeric value.  Within SQL Server, Microsoft allows you to define a column with an identity property to help generate surrogate key values.

A natural key is a single column or set of columns that uniquely identifies a single record in a table

A surrogate key like a natural key is a column that uniquely identifies a single record in a table.  But this is where the similarity stops.  Surrogate keys are similar to surrogate mothers.   They are keys that don’t have a natural relationship with the rest of the columns in a table.  The surrogate key is just a value that is generated and then stored with the rest of the columns in a record.  The key value is typically generated at run time right before the record is inserted into a table.   It is sometimes also referred to as a dumb key, because there is no meaning associated with the value.  Surrogate keys are commonly a numeric number.  

Thursday, 11 June 2015

Use ViewState in diffrent page



If you want to use only viewstate to send data to next page, then you should use the server.transfer() method instead of resposnse.redirect() method. Let us suppose we want to pass viewstate on click of a button as below:

    public void btnSer_OnClick(object sender, EventArgs e)
    {

        ViewState["yourvalue"] = "sujoy santra";
        ViewState["yourcity"] = "kolkata";
        Server.Transfer("Default.aspx");

    }

on the same page create a method of the class statebag

     public StateBag ReturnViewState()
    {
        return ViewState;
    }

Now on the page where you want to transfer let here be Default.aspx. Place the following function in Default.aspx.cs file

private StateBag PreviousPageViewState
    {
        get
        {
            StateBag returnValue = null;
            if (PreviousPage != null)
            {
                Object objPreviousPage = (Object)PreviousPage;
                MethodInfo objMethod = objPreviousPage.GetType().GetMethod("ReturnViewState");//System.Reflection class
                return (StateBag)objMethod.Invoke(objPreviousPage, null);

            }
            return returnValue;
        }
    }

Now let us find the values of viewstate of previous page( ViewState["yourvalue"] and ViewState["yourcity"])

let us do it at page load of Default.aspx

    protected void Page_Load(object sender, EventArgs e)
    {
        if (PreviousPage != null && PreviousPageViewState != null)
        {
            var sg = PreviousPageViewState["yourvalue"].ToString();
            var nev = PreviousPageViewState["yourcity"].ToString();
        }
    }

So we are done. you can access the viewstate value of previous page.

Notification Bubble using CSS

Notification bubble using CSS.

<style type="text/css">
        .notification{
            height: 14px;
            -moz-border-radius: 36px;
            border-radius: 36px;
            width: 14px;
            padding: 3px;
            display: inline-block;
            color: #fff;
            text-shadow: 0px 1px 1px #707070;
            font-weight: bold;
            font-family: helvetica;
            text-align: center;
            font-size: 12px;
            top: -13px;
            right: 10px;
            position: absolute;
        }
     
        .pink{
            background-color: #f4a1b2;
            border: 1px solid #cf5161;
            background: -webkit-linear-gradient(top, #f4a1b2 0%, #f56879 100%);
            background: -moz-linear-gradient(top, #f4a1b2 0%, #f56879 100%);
            background: -ms-linear-gradient(top, #f4a1b2 0%, #f56879 100%);
            background: -o-linear-gradient(top, #f4a1b2 0%, #f56879 100%);
            background: linear-gradient(top, #f4a1b2 0%, #f56879 100%);
            filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f4a1b2', endColorstr='#f56879',GradientType=0 );
        }

        .yellow{
            background-color: #fecf63;
            border: 1px solid #e8aa44;
            background: -webkit-linear-gradient(top, #fee499 0%, #febc4b 100%);
            background: -moz-linear-gradient(top, #fee499 0%, #febc4b 100%);
            background: -ms-linear-gradient(top, #fee499 0%, #febc4b 100%);
            background: -o-linear-gradient(top, #fee499 0%, #febc4b 100%);
            background: linear-gradient(top, #fee499 0%, #febc4b 100%);
            filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fee499', endColorstr='#febc4b',GradientType=0 );
        }

        .blue{
            background-color: #91daf6;
            border: 1px solid #7cb7cd;
            background: -webkit-linear-gradient(top, #c2ecfa 0%, #71cef3 100%);
            background: -moz-linear-gradient(top, #c2ecfa 0%, #71cef3 100%);
            background: -ms-linear-gradient(top, #c2ecfa 0%, #71cef3 100%);
            background: -o-linear-gradient(top, #c2ecfa 0%, #71cef3 100%);
            background: linear-gradient(top, #c2ecfa 0%, #71cef3 100%);
            filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#c2ecfa', endColorstr='#71cef3',GradientType=0 );
        }
    </style>


<div id="div_notification" runat="server" class="notification pink">
                                    <asp:Label ID="lblNotification" runat="server" Text="2"></asp:Label></div>

Get value of BoundField column set to Visible=False in GridView

 When you set Visible property to False for a BoundField column then it is not possible to get value of such column and hence you need to make use of DataKeyNames (DataKeys) property of ASP.Net GridView.

What are DataKeyNames and DataKeys?
      DataKeyNames is the property of GridView which allows us to set the names of the Column Fields that we want to use in code but do not want to display it. Example Primary Keys, ID fields, etc.
The values Column Fields which are set in DataKeyNames are available in code in DataKeys object which saves it in an Array called as DataKeyArray.

 Using DataKeyNames and DataKeys in GridView
   Using DataKeyNames and DataKeys is fairly simple, you just need to set the name of the Column in DataKeyNames property as shown below. Here CustomerId is the name of the Column.
DataKeyNames="CustomerId"

And then in code access it using the RowIndex of the GridView Row to get the value of the Column for that particular Row.
int id = Convert.ToInt32(GridView1.DataKeys[rowIndex].Values[0]);







 Getting the DataKeys value for a particular GridView Row
Inside the Button click event handler, first the GridView Row is determined using the NamingContainer property and then finally the Row Index is determined.
Using the Row Index, the DataKeys array is accessed and the value of the Column is fetched.
C#
protected void GridView_Button_Click(object sender, EventArgs e)
{
    //Determine the RowIndex of the Row whose Button was clicked.
    int rowIndex = ((sender as Button).NamingContainer as GridViewRow).RowIndex;

    //Get the value of column from the DataKeys using the RowIndex.
    int id = Convert.ToInt32(GridView1.DataKeys[rowIndex].Values[0]);
}

VB.Net
Protected Sub GridView_Button_Click(sender As Object, e As EventArgs)
    'Determine the RowIndex of the Row whose Button was clicked.
    Dim rowIndex As Integer = TryCast(TryCast(sender, Button).NamingContainer, GridViewRow).RowIndex

    'Get the value of column from the DataKeys using the RowIndex.
    Dim id As Integer = Convert.ToInt32(GridView1.DataKeys(rowIndex).Values(0))
End Sub

Wednesday, 3 June 2015

What is difference between RowCreated & RowDataBound events?

 Gridview RowCreated is fired before then RowDataBound Event. If we apply any styles to Gridview Controls we have to choose RowDataBound Event.

But the signature of the RowCreated and RowDataBound events has same signature so everyone doing some confusion which event i need to choose.


  protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='red'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='green'");
        }
                                         // Not Preferred
  
    }

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='orange'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='blue'");
        }
                             // Good Programming
    }

Note: If we apply style to apply in RowCreated and RowDataBound evnts. the styles in RowDataBound event is applied why because RowCreated styles are override by RowDataBound event. as well if don't written any style in RowDataBound event then RowCreated Event Style are applicable.

Tuesday, 2 June 2015

What are the differences between foreign, primary, and unique keys

While unique and primary keys both enforce uniqueness on the column(s) of one table, foreign keys define a relationship between two tables.
A foreign key identifies a column or group of columns in one (referencing) table that refers
to a column or group of columns in another (referenced) table.

What is d difference between overriding and overloading ?

Overloading

a)In this approach we can define multiple   methods with same name changing their signature means different parameters

b) This can be performed within class as well as  within child class

c) Doesn't require any permission from parent  for overloading its method in child

Overriding

 a.It is an approach of defining multiple methods with same name and same signature

b. this can be performed only under child class

c. Requires an explicit permission from parent  to override its methods in child

Diffrence between ExecuteScalar() and ExecuteNonQuery()

ExecuteScalar() Method:

ExecuteScalar() method is used to retrieve a single value from database. It executes the defined query and returns the value in the first column of the first row in the selected result set and ignores all other columns and rows in the result set. It is use to get aggregate value from database, for example count or total of rows. So it works with non action queries that use aggregate functions. ExecuteScalar() method is a faster way when we compare it to other ways to retrieve single value from database. It returns a value as object and we have to cast it to appropriate type.


ExecuteNonQuery() Method:

ExecuteNonQuery() method is used to manipulate data in database and is used for statements without results such as CREATE, INSERT, UPDATE and DELETE commands. It does not return any data but it returns number of rows affected. If NO COUNT property is ON then it will not return number of rows affected. It will not give access to result set generated by the statement. The return value of number of rows affected is of type integer and you can get it in an integer variable. It will tell you how many rows have been affected in result of your statement. ExecuteNonQuery() method is a flexible method and we can use it input and output parameters.