I have a datatable, i want to get distinct rows on the basis of value of one column instead of getting distinct rows on basis of all column in row of datatable. since we can get distinct rows as follows
datatableName.DefaultView.ToTable("true","ColName");
since in ToTable() we have to specify all column to be displayed. Please help me so that i can be able to get distinct rows having all column displyed and only one column is used to get distinct rows.
Example sample rows, which i have are as follows
ID Application English Spanish German
1 sam thnks thnkd t开发者_如何学JAVAhkng
2 smp thnks thnke thnkp
3 anp same same same
i want to get all those rows wwhich have different spanish/German Cloumn Value against English Column Value.....
Help in this regard will be much appreciated...
Thanks in advance
If you are looking for how to find rows where the columns do not match, thats easy
SELECT * FROM table WHERE column2 != column3
But for a realy distinct you have to run distict over all the columns you need as distinct meens that the rows are not identical.
YOu could also have a sub select with distinct on 2 collumns and then join in the rest of the columns if you like.
When you say "i want to get all those rows wwhich have different spanish/German Cloumn Value against English Column Value...", that is not what DISTINCT means, that is a filter.
You can just do this:
datatableName.DefaultView.RowFilter = "English <> German";
DataTable result = datatableName.DefaultView.ToTable("differentEngGer");
datatableName.DefaultView.RowFilter = null; //reset the view to not filter anything
You could do
var x = (from r in dt.AsEnumerable() select r["ABC"]).Distinct().ToList(); //dt is the datatable
Hope this help
got answer from msdn forum here
you can try following code.
datatableName.DefaultView.ToTable("true","ID","Application","English","Spanish","German");
精彩评论