XML and Select Distinct

  • Thread starter Thread starter Matt Tapia
  • Start date Start date
M

Matt Tapia

I have an XML file that I have stored in ado.net dataset. What I want to do
is a SELECT DISTINCT on one of the columns (or individual tag) of table tag.
How can I do this?
 
AFAIK,

Ado.net does not support aggregate functions, so you would have to write
code like as below on your datatable

int distinctcounter = 0;
foreach(DataRow row in yourtable.rows)
{
if(distinctcounter!= row["yourdistinctercolumn"])
{
newTable.AddRow(row);
distinctcounter= row["yourdistinctercolumn"];
}
}

Or if you wanna go hitech, create a second table that has primary keys that
match the column you wanna be distinct on, plus a count column. Then for
each row in your source table, add or update the count in this second table.
Then use DataTable.Rows.Find to find the matching row ... .. I know I know
it isn't fair, but life isn't either.

Does XPath let you do Uniques? Hmmmmm ..

Or hey look what I found :) hehe -
http://support.microsoft.com/default.aspx?scid=kb;EN-US;326176

- Sahil Malik
Independent Consultant
You can reach me thru my blog - http://dotnetjunkies.com/WebLog/sahilmalik/
 
Back
Top