Pages

Showing posts with label session. Show all posts
Showing posts with label session. Show all posts

Tuesday, September 24, 2013

Copy unique rows of a column from one Datatable to other Datatable - LINQ



Here , We have to copy the unique rows of column 'CategoryName' from DataTable 'dt_old' to the 'Category' column of DataTable 'dt_Categories' using LINQ.


 DataTable dt_Categories = new DataTable();
 dt_Categories.Columns.Add("Category", Type.GetType("System.String"));

DataTable dt_old = new DataTable();
dt_old = (DataTable)Session["dt"];


 dt_Categories = dt_old.AsEnumerable().Select(row =>
            {
                DataRow newRow = dt_Categories.NewRow();
                newRow["Category"] = row.Field<string>("CategoryName");
                return newRow;
            }).Distinct(DataRowComparer.Default).CopyToDataTable();






Saturday, August 3, 2013

Session is null problem in Handler-C#

System.Web.SessionState.IRequiresSessionState
  
Add this red line in your code as same as in example given below:


<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;

public class Handler : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
    public void ProcessRequest(HttpContext context)
    {
        context.Session["abc"] = "ankit";    // use session
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    } 
}