您的位置:首页 > 其它

如何去掉DataTable中的重复行

2008-11-20 17:38 357 查看
public DataTable GetTopSearch()

{

{

string keyword = dsKeyword.Tables[0].Rows[i]["Name"].ToString();

string condition = dsKeyword.Tables[0].Rows[i]["SearchCondition"].ToString();

dsTopSearch.Merge(dal.GetTopSearch(keyword,condition));

}

return dsTopSearch.Tables[0].DefaultView.ToTable(true, "ID","Name","Author","Publisher","PublishDate","TypeName","Price","SalePrice","SavePrice","Rebate","ImagePath","ContentIntro");

}

先把DataTable转成DataView,再通过DataView.ToTable()转回DataTable,ToTable()方法中有一个重载可以轻松消除重复行.

注:该重载的第二个参数为要保存的字段名.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: