"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Wednesday, January 30, 2013

Remove Duplicate Row from datatable in c#

As i was also unaware of this feature until i read as answer in fourms.asp.net (link). Previously i was achieved by using lambda expression.Now no need to those just one line code :)


DataTable dt = new DataTable
        {
            Columns ={
                {"Myid",typeof(int)},
                {"Name"},
                {"Address"}
                }
        };
        dt.Rows.Add(1, "Arun Aravind", "Kollam");
        dt.Rows.Add(1, "Arun Aravind", "Kollam");
        dt.Rows.Add(2, "Arun Aravind", "Kollam");
        dt.Rows.Add(2, "Arun Aravind", "Kollam");
        dt.Rows.Add(3, "Arun Aravind", "Kollam");

        dt = dt.DefaultView.ToTable(false, "Address", "Name", "Myid");

Output




If u had any trouble just ask, Happy to help u :)
Stay Tune... Have a nice day... 'N happy Coding :)

No comments: