怎么删除datatable或dataset中相同的行

来源:百度知道 编辑:UC知道 时间:2024/05/20 12:05:15
怎么在C#中删除datatable或dataset中相同的行
问题是不能用SQL
只能得到dataset 或datatable后才去消相同行

没有别的办法,只能自己每行比较,然后删除
Hashtable hash=new Hashtable();
for(int n=0;n<rowscount;n++)
{
//get key
object hashKey=hashKeyOfRow(rows[n]);
if(hash.contains(hashKey))
{
//remove row
n=Math.max(0,n-1);
}
else
{
hash.add(hashKey);
}
}

你用sql查询时就把重复的删除 不就行了嘛

我的想法也是啊,SQL删除

在sql中,当要查询时在列前用distinct就可以排除相同的行,
如:
use Northwind
go
select distinct productName from productTable

没有好办法,只能遍历每条记录的所有字段