ASP.NET 2.0 DataView - Select by DISTINCT

Assuming you has this scenario. 2 DataTable(s) which you grabbed data from the database. Then you will merge the DataTable1 to DataTable2 within your Business Rule class.

 

Example,

 

dTable1.Merge(dTable2);

 

Now you will noticed that there are 2 rows of data which have similar data. You are curious on how you can select a distinct from these DataTable so it will not show duplicate data. You do not plan to rely on stored proc to handle this.

 

You can do select statement with DataTable, however it is not possible with DISTINCT. So for my case, I have use DataView instead to do the DISTINCT and then cast it to a DataTable like this:

 

DataTable dTest = dView.ToTable(true, "ResearchID", "ResearchTitle", "ConsultantID", "ConsultantName", "StartDate", "EndDate");

 

Just take note, the argument 2 onwards are your columns. You have to put all your columns here. Assuming originally your data inside your DataTable has 5 columns, you have to put all 5 columns here.

 

Cheers.

Published Monday, December 11, 2006 3:11 PM by chuawenching

Comments

# Theodore

Monday, August 11, 2008 1:55 PM by Augustus

766747c00a06d2b9c989a2636edc5e29

<a href="njdokj.info/.../766747c00a06d2b9c989a2636edc5e29">">njdokj.info/.../766747c00a06d2b9c989a2636edc5e29"> njdokj.info/.../766747c00a06d2b9c989a2636edc5e29 </a>

njdokj.info/.../766747c00a06d2b9c989a2636edc5e29

[url]njdokj.info/.../766747c00a06d2b9c989a2636edc5e29[url]