Sunday, 29 March 2015

HTML DOM lastModified Property

Example

Get the date and time the current document was last modified:
var x = document.lastModified;
The result of x will be:
11/13/2014 10:05:21

More "Try it Yourself" examples below.

Definition and Usage

The lastModified property returns the date and time the current document was last modified.
Note: This property is read-only.

Browser Support

Property




lastModified Yes Yes Yes Yes Yes

Syntax

document.lastModified

Technical Details

Return Value: A String, representing the date and time the document was last modified
DOM Version Core Level 3 Document Object

More Examples

Example

Convert the lastModified property into a Date object:
var x = new Date(document.lastModified);
The result of x will be:
Thu Nov 13 2014 10:05:21 GMT-0800 (Pacific Standard Time)

Sunday, 22 March 2015

Difference between ArrayList and Generic List in C# .Net

In this article I will explain difference between ArrayList and Generic List in C# .Net and VB.Net.
ArrayList
1. ArrayList belongs to the System.Collections namespace, i.e. you need to import the following namespace.
C#
using System.Collections;
 
2. ArrayList does not have type restriction for storing data i.e. it is not Type Safe. You can store anything in ArrayList. In fact same ArrayList can store multiple types of objects.
C#
ArrayList arrList = new ArrayList();
arrList.Add(921);
arrList.Add("Mudassar Khan");
arrList.Add(DateTime.Now);
 
 
3. ArrayList stores all data as object thus to get it back you must remember what you stored where and correspondingly Type Cast it as per its original Type when stored.
C#
int number = Convert.ToInt32(arrList[0]);
string name = arrList[1].ToString();
DateTime dt = Convert.ToDateTime(arrList[2]);
 
4. ArrayList is mainly for .Net 2.0 Framework projects as during that period Generic List was not invented.
5. While running a Loop on ArrayList you need to use Object data type. Thus this is another disadvantage as you again do not know what type of data particular item contains.
C#
foreach (object o in arrList)
{
 
}
 
Generic Lists (List<T>)
1. Generic List (List<T>) belongs to the System.Collections.Generic namespace, i.e. you need to import the following namespace.
C#
using System.Collections.Generic;
 
2. In Generic List (List<T>), T means data type, i.e. string, int, DateTime, etc. Thus it will store only specific types of objects based on what data type has been specified while declarations i.e. it is Type Safe. Thus if you have a Generic List of string you can only store string values, anything else will give compilation error.
Below I had no option other than having three different Generic Lists for three different data types.
C#
List<string> lstString = new List<string>();
lstString.Add("Mudassar Khan");
lstString.Add("Robert Hammond");
lstString.Add("Ramesh Singh");
 
List<int> lstInt = new List<int>();
lstInt.Add(991);
lstInt.Add(10);
lstInt.Add(4450);
 
List<DateTime> lstDateTime = new List<DateTime>();
lstDateTime.Add(DateTime.Now);
lstDateTime.Add(DateTime.Now.AddDays(20));
lstDateTime.Add(DateTime.Now.AddHours(-10));
 
3. Generic List stores all data of the data type it is declared thus to getting the data back is hassle free and no type conversions required.
C#
int number = lstInt[0];
string name = lstString[0];
DateTime dt = lstDateTime[0];
 
 
4. Generic List must be used instead of ArrayList unless specific requirement for projects higher than .Net 2.0 Framework.
5. While running a Loop on Generic List again it is problem free as we exactly know what the List contains.
C#
foreach (int number in lstInt)
{
}
foreach (string name in lstString)
{
}
foreach (DateTime dt in lstDateTime)
{
}
 
 

Sum previous Salary using sql and show all years


select EmpID,
  (
  select sum(sub.Salary) as Sub_Salary from Employee sub where sub.EmpID<=main.EmpID
  ) as Sub_Salary
from Employee main

Friday, 20 March 2015

Different Types of SQL Keys

  • Alternate key - An alternate key is any candidate key which is not selected to be the primary key
  • Candidate key - A candidate key is a field or combination of fields that can act as a primary key field for that table to uniquely identify each record in that table.
  • Compound key - compound key (also called a composite key or concatenated key) is a key that consists of 2 or more attributes.
  • Primary key - a primary key is a value that can be used to identify a unique row in a table. Attributes are associated with it. Examples of primary keys are Social Security numbers (associated to a specific person) or ISBNs (associated to a specific book). In the relational model of data, a primary key is a candidate key chosen as the main method of uniquely identifying a tuple in a relation.
  • Superkey - A superkey is defined in the relational model as a set of attributes of a relation variable (relvar) for which it holds that in all relations assigned to that variable there are no two distinct tuples (rows) that have the same values for the attributes in this set. Equivalently a superkey can also be defined as a set of attributes of a relvar upon which all attributes of the relvar are functionally dependent.
  • Foreign key - a foreign key (FK) is a field or group of fields in a database record that points to a key field or group of fields forming a key of another database record in some (usually different) table. Usually a foreign key in one table refers to the primary key (PK) of another table. This way references can be made to link information together and it is an essential part of database normalization

Remove Duplicate Records by using ROW_NUMBER()

CREATE TABLE dbo.Employee
(
EmpID int IDENTITY(1,1) NOT NULL,
Name varchar(55) NULL,
Salary decimal(10, 2) NULL,
Designation varchar(20) NULL
 )
  insert Employee values('Amit',12000,'SE')
 insert Employee values('Mohan',15000,'SE')
 insert Employee values('Monu',27000,'SSE')
 insert Employee values('Riyaz',16000,'SE')
insert into Employee
select Name,Salary,Designation from Employee
select * from Employee

with tmpEmp (Name,DuplicateRowCount)
as
(
select Name,row_number() over(partition by Name,Salary order by name) as DuplicateRowCount
from Employee
)
delete from tmpEmp where DuplicateRowCount>1
select * from Employee

Thursday, 19 March 2015

Add shoring in gridview

//Sorting enable and generate event
<asp:GridView runat="server" ID="grvPaymentsList" EnableViewState="true" AutoGenerateColumns="false" OnSorting="grvAcceptDDPaymentsList_Sorting" AllowSorting="true" ShowFooter="true" OnRowDataBound="grvAcceptDDPaymentsList_RowDataBound">


//Define Column
<asp:TemplateField HeaderText="Payment Date" SortExpression="ApplicationDate">
                    <ItemTemplate>
                        <asp:Label Text='<%# Eval("ApplicationDate") %>' ID="lblApplicationDate" runat="server"></asp:Label>
                    </ItemTemplate>

                </asp:TemplateField>

//OnPageLoad
 //Fill ViewState
ViewState["dt"] = dt;


 protected void grvAcceptDDPaymentsList_Sorting(object sender, GridViewSortEventArgs e)
    {
        try
        {
            SetSortDirection(SortDireaction);
            DataTable dataTable = (DataTable)ViewState["dt"];
            if (dataTable != null)
            {
                //Sort the data.
                dataTable.DefaultView.Sort = e.SortExpression + " " + _sortDirection;
                grvAcceptDDPaymentsList.DataSource = dataTable;
                grvAcceptDDPaymentsList.DataBind();
                SortDireaction = _sortDirection;
            }
        }
        catch (Exception ex)
        {
            ShowMessage(ex.Message, "E");
        }
    }

    private void SetSortDirection(object SortDireaction)
    {
        if (sortDirection == "ASC")
        {
            _sortDirection = "DESC";
        }
        else
        {
            _sortDirection = "ASC";
        }
    }
    public string _sortDirection { get; set; }

    public string sortDirection { get; set; }

    public string SortDireaction { get; set; }

Wednesday, 4 March 2015

An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.



Config setting
The 2nd option is the one you want.
In your web.config, make sure these keys exist:
<configuration>
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
    </system.webServer>
</configuration>