Friday, November 14, 2008

Some LINQ Queries

TestDataContext TDC = new TestDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        var query = from table in TDC.PTables
                    where table.salary >= 10000
                    orderby table.Age descending
                    select new
                    {
                        Name = table.Name.ToUpper(),
                        Age = table.Age,
                       Country = table.Country

                    };

        gv1.DataSource = query;
        gv1.DataBind();
      



      //Showing a List of Process by LINQ
      var process = from p in System.Diagnostics.Process.GetProcesses()
                      orderby p.ProcessName
                    select new
                     {
                        p.ProcessName,
                          p.Id,
                         p.Threads,
                          p.HandleCount,
                          p.WorkingSet64
                          

                     };
      foreach (var test in process)
       {
           Response.Write(test+"
");
       }



      //Showing a List of Files by LINQ
        System.IO.DirectoryInfo DI  = new System.IO.DirectoryInfo("D:\\USBBackUP\\Cards\\Cards");

       var directoryList =
                from f in DI.GetFiles("*.*",
                System.IO.SearchOption.AllDirectories)
              select f;

      foreach( var row in directoryList)
       {
            Response.Write(row +"
");
       }
    }
   
    protected void btnInsert_Click(object sender, EventArgs e)
    {
        
        PTable ptable = new PTable();
        ptable.Age = "35";
        ptable.Name = "Nitin Sharma";
        ptable.Country = "INDIA";

        TDC.PTables.InsertOnSubmit(ptable);
        TDC.SubmitChanges();
        gv1.DataBind();

        
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
       
        try
        {
            PTable todelete = TDC.PTables.Single(p => p.Name.Contains("Nitin"));
            TDC.PTables.DeleteOnSubmit(todelete);
            TDC.SubmitChanges();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
        gv1.DataBind();
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        var update = (from table in TDC.PTables
                     where table.CountryID == 8 
                     select table).Single();
        update.Name = txtName.Text;
        TDC.SubmitChanges();
        gv1.DataBind();
        txtName.Text = "";
       
       
        
    }

      

Thanks,
Nitin Sharma

Wednesday, November 5, 2008

Joins in LINQ


Using a Simple Join in LINQ:

 RekabuDataContext RKdb = new RekabuDataContext();

protected void Page_Load(object sender, EventArgs e)
    {
     
        BindGridView();
       
    }

public void BindGridView()
    {
        var q = from records in RKdb.Tests
                from recordsnew in RKdb.Images
                where records.id == recordsnew.id
                select recordsnew;
        gvRekabu.DataSource = q;
        gvRekabu.DataBind();
    }


Assigning Custom Columns header in LINQ:

public void Bind()
    {

        var q = from fields in RKdb.Tests
                where (fields.salary >= 20000)

                select new
                {
                    CandidateName = fields.Name,
                    CandidateLocation = fields.Loaction,
                    CandidateSalary = fields.salary,

                }
                ;

        gvRekabu.DataSource = q;
        gvRekabu.DataBind();
    
    }


Thanks,
Nitin Sharma

Tuesday, November 4, 2008

Tulsi Vivah on November 10,2008

Tulsi Vivah

The tulsi plant is held sacred by the Hindus as it is regarded as an incarnation of Mahalaxmi who was born as Vrinda. The festival of Tulsi Vivah is celebrated in each and every household of Goa. The one special feature of the festival is that of preparing various delicious sweet dishes at home. The women folk engage themselves in preparations well in advance. A typical Goan ojhe (load of sweets) is sent to the daughter from her parental home along with jodi (cotton threads used to light lamp while performing aarti). 

Tulsi was married to demon king Jalandhar. But she prayed to Lord Vishnu that her demon husband would be protected, with the result that no god was able to harm him. However on the request of the other gods, Lord Vishnu took the form of Jalandhar and stayed with the unsuspecting Tulsi. When the truth emerged after Jalandhar's death, Vrinda crused Vishnu and turned him to stone (Shaligram) and collapsed. From her body emerged the tulsi plant. That is why Vishnu pooja is considered incomplete without tulsi leaves. Tulsi vivah is celebrated on the next day of Kartiki Akadashi. On this day tulsi is married to Shaligram. 

On this day tulsivrindavan is coloured and decorated as a bride. Sugarcane and branches of tamarind and amla trees are planted along with the tulsi plant. Only vegetarian food is cooked on this day. At midday, a full meal consisting of rice, moongachi gathi, puri , sweet potato kheer , red pumpkin vegetable cooked with pieces of sugarcane, amla and tamarind is offered to Tulsi Vrindavan. Tulsi vivah ceremony takes place in the late evening. Various poha dishes are offered to Lord Vishnu. Then prasad is distributed among family members and friends.


Thanks,
Nitin Sharma

Tuesday, October 21, 2008

Dispose VS Finalize

1. Finalize() is the C# equivalent of destructor ~Object() syntax in C#. In VB.Net you implement the Finalize() by overriding it. But, in C# the compiler translates the destructor to a Finalize() method. 

2. Finalize() can NOT be overridden or called in C#. 

3. Since, Finalize() is called by the Garbage Collector, it is non-deterministic. 

4. Dispose() has to be implemented in classes implementing IDispose interface. 

5. Its the right place for freeing-up unmanaged resources like file, handles, and connections etc. 

6. Dispose() method is called explicitly in the code itself. 

7. Dispose() method is automatically called (for objects which implement IDispose), when used in a "using" statement.


Thanks,
Nitin Sharma

Gunas

The Gunas

According to the Sankhya philosophy, Prakriti is composed of three Gunas or forces, called Sattva (purity, light, harmony), Rajas (passion, activity, motion) and Tamas (inertia, darkness, inertness, inactivity).

 

Guna means a cord. The Gunas bind the soul with a triple bond. These Gunas are not the Nyaya-Vaiseshika Gunas. They are the actual substances or ingredients, of which Prakriti is constituted. They make up the whole world evolved out of Prakriti. They are not conjoined in equal quantities, but in varying proportions, one or the other being in excess. Just as Sat-Chit-Ananda is the Vedantic trinity, so also the Gunas are the Sankhyan trinity.

 

Interaction Between the Gunas Leads to Evolution

The three Gunas are never separate. They support one another. They intermingle with one another. They are intimately related as the flame, the oil and the wick of a lamp. They form the very substance of Prakriti. All objects are composed of the three Gunas. The Gunas act on one another. Then there is evolution or manifestation. Destruction is only non-manifestation.

 

The Gunas are the objects. Purusha is the witness-subject. Prakriti evolves under the influence of Purusha. Mahat or the Great (Intellect), the Cause of the whole world, is the first product of the evolution of Prakriti. Ahankara arises after Buddhi. Agency belongs to Ahankara. It is the principle that creates individuality. Mind is born of Ahankara. It carries out the orders of the will through the organs of action (Karma Indriyas). It reflects and doubts (Sankalpa-Vikalpa). It synthesises the sense-data into percepts. The mind takes part in both perception and action. There is no separate Prana Tattva in the Sankhya system. The Vedanta system has a separate Prana Tattva. In the Sankhya system, mind, with the organs, produces the five vital airs. Prana is a modification of the senses. It does not subsist in their absence.

 

Characteristics of the Three Gunas

Sattva is equilibrium. When Sattva prevails, there is peace or tranquillity. Rajas is activity which is expressed as Raga-Dvesha, likes or dislikes, love or hatred, attraction or repulsion. Tamas is that binding force with a tendency to lethargy, sloth and foolish actions. It causes delusion or non-discrimination.

 

When Sattva is predominant, it overpowers Rajas and Tamas. When Rajas is dominant, it overpowers Sattva and Tamas. When Tamas is predominant, it overpowers Rajas and Sattva.

 

How Man Is Affected by the Three Gunas

There are three Gunas in every man. Sometimes, Sattva prevails in him. Then he is calm and tranquil. He reflects and meditates. At other times, Rajas prevails in him and he does various sorts of worldly activities. He is passionate and active. Sometimes, Tamas prevails. He becomes lazy, dull, inactive and careless. Tamas generates delusion.

 

Again, one of these Gunas is generally predominant in different men. A Sattvic man is virtuous. He leads a pure and pious life. A Rajasic man is passionate and active. A Tamasic man is dull and inactive.

 

Sattva makes a man divine and noble, Rajas makes him thoroughly human and selfish, and Tamas makes him bestial and ignorant. There is much Sattva in a sage or saint and there is much Rajas in a soldier, politician and businessman.


Thanks,

Nitin Sharma