c# - 使行不同并显示所有列

标签 c# datatable dataset dataview

在我的项目中有两个数据表dtFaildtFailed(dtFailed 除了列名声明外什么都没有)。 dtFail 具有重复的“EmployeeName”列值。所以我拿了一个数据 View dvFail 并做了使它们不同的过程,如下面的代码所示:

dtFail

enter image description here

我尝试了下面的代码:

   DataView dvFail = new DataView(dtFail);
   dtFail = dvFail.ToTable(true, "EmployeeName"); //showing only one column in dtFail

dtFailed(只有一列)

enter image description here

如果我喜欢下面

   DataView dvFail = new DataView(dtFail);
   dtFail = dvFail.ToTable(true, "EmployeeName","EmployeeRole","Status");

dtFailed(显示但有重复的行)

enter image description here

然后数据表 dtFailed 也存储了重复的“EmployeeName”。

请帮忙
提前致谢。

最佳答案

试试这个查询-

DataTable distinctTable = originalTable.DefaultView.ToTable( /*distinct*/ true);

有关更多信息,请点击以下链接-

https://social.msdn.microsoft.com/Forums/en-US/ed9c6a6a-a93e-4bf5-a892-d8471b84aa3b/distinct-in-datatable-or-dataview?forum=adodotnetdataset

希望对您有所帮助。

关于c# - 使行不同并显示所有列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12986486/

相关文章:

c# - 在 C# 中使用 .NET 3.5 将数据集转换为 JSON

asp.net - 为什么我应该或不应该将数据集、数据表等作为 session 变量存储在 ASP.NET 页面中?

javascript - 将大型数据集传递给客户端——Javascript 数组还是 JSON?

c# - 如何运行一个 c# WinForm 应用程序实例?

c# - StackPanel 逆序 - WPF

c# - 在哪里可以了解有关 P/Invoke 的更多信息?

c# - WCF 数据服务 (CTP2) : There is a type mismatch between the client and the service

c# - 使用 XmlSerializer 将 DataTable 反序列化为自定义类

javascript - 数据表子行

R Shiny : Click Button Within Datatable to Display Popup Twice in a row