20 June 2014

How to remove duplicate records from datatable in c#



 private DataTable RemoveDuplicatesRecords(DataTable dt)
 {
    var UniqueRows = dt.AsEnumerable().Distinct(DataRowComparer.Default);
    DataTable dt2 = UniqueRows.CopyToDataTable();
    return dt2;
  }

19 June 2014

Difference between a Class and an object ?


Class: 
1)It is a datatype that contains the programming logic. 
2)Class is visible in the source code and resides in hard disk. 
3)Class is like a template or blueprint of the object. It implements reusability, 
encapsulation, inheritance 
example:Button is a class with properties like Text,BackColor, 
events like click, methods like Focus 

Object: 
1)it is a chunk of memory that implements the class logic. 
2)Object is in the RAM and not visible in source code. 
3)It is the real world implementation of the class. 
Each object has its own copy of data. 
example: Button1, Button2 are the objects of Button class.

Difference between Value Type and Reference Type ?




Value type
Reference type
Value type they are stored on stack
Reference type they are stored on heap
When passed as value type new copy is created and passed so changes to variable does not get reflected back
When passed as Reference type then reference of that variable is passed so changes to variable does get reflected back
Value type store real data
Reference type store reference to the data.
Value types are faster in access
Reference types are slower in access.
Value types derive fromSystem.ValueType
Reference types derive fromSystem.Object
Value type consists of primitive data types, structures, enumerations.
Reference type consists of class, array, interface, delegates
Value types can not contain the valuenull.
Reference types can contain the valuenull.

Converting Array to List



using System.Linq;

List<datatype> list = array.ToList();

Comparing two datatables and returning a datatable by matching rows in c#.net using linq



  public DataTable get_Comparing(DataTable dt1, DataTable dt2)
   {
      DataTable dtMerged = (from a in dt1.AsEnumerable()
                                  join b in dt2.AsEnumerable()
                            on a["Student_Id"].ToString() equals b["Student_Id"].ToString()
                                  into g
                                  where g.Count() > 0
                                  select a).CopyToDataTable();

            return dtMerged;
   }

11 June 2014

How to find nearest location using latitude and longitude from sql



Table Strcture :-

Create table tbl_locations(Id int identity(100,1) primary key,Name varchar(100),Address varchar(200),Latitude varchar(50),Longtitude varchar(50)

NOTE - Here latitude = 12.994267 & longitude = 77.672940. So you just pass your own.

Select Query

SELECT Id,Name,( 3959 * acos( cos( radians(12.994267) ) * cos( radians( Latitude ) ) * cos( radians( Longtitude ) - radians(77.672940) ) + sin( radians(12.994267) ) * sin( radians( Latitude ) ) ) ) AS Distance FROM tbl_locations ORDER BY Distance

How do I refresh the page in ASP.NET using C#.net?

Response.Redirect(Request.RawUrl);