Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

making rows distinct and showing all the columns

In my project there are two datatables dtFail and dtFailed (dtFailed has nothing but column names declarations). dtFail has duplicate "EmployeeName" column values. so i took a dataview dvFail and did the process to make them distinct as shown in the below code:

dtFail

enter image description here

I tried the below code:

   DataView dvFail = new DataView(dtFail);
   dtFail = dvFail.ToTable(true, "EmployeeName"); //showing only one column in dtFail

dtFailed (only one column)

enter image description here

If i do like below

   DataView dvFail = new DataView(dtFail);
   dtFail = dvFail.ToTable(true, "EmployeeName","EmployeeRole","Status");

dtFailed (showing but with duplicate rows)

enter image description here

Then the datatable dtFailed is storing duplicate "EmployeeName" also.

Please Help
Thanks in Advance.

like image 412
Mr_Green Avatar asked Oct 20 '12 07:10

Mr_Green


1 Answers

Try this query-

DataTable distinctTable = originalTable.DefaultView.ToTable( /*distinct*/ true);

For more info hit below link-

https://social.msdn.microsoft.com/Forums/en-US/ed9c6a6a-a93e-4bf5-a892-d8471b84aa3b/distinct-in-datatable-or-dataview?forum=adodotnetdataset

I hope this would have helped you.

like image 187
ShaileshDev Avatar answered Oct 14 '22 00:10

ShaileshDev