简体   繁体   English

我们如何在C#中过滤数据表?

[英]How can we filter datatable in c#?

I have specific requirement with datatable which i am not able to get. 我对无法获得的数据表有特定要求。 Please help me to solve my problem. 请帮助我解决我的问题。 My query is as below 我的查询如下

  1. The datatable i have with data is 我与数据的数据表是
  C1 C2 C3 C4 C5 R1 1 2 3 4 25 R2 6 7 8 24 10 R3 11 22 13 14 15 R4 16 17 23 19 20 R5 21 7 18 9 5 
  1. In output i would like to have max value from each colum with position (index) of row and colum as following 在输出中,我希望每个列的最大值(行和列的位置(索引)如下)
 Value Row Column 21 R5 C1 22 R3 C2 23 R4 C3 24 R2 C4 25 R1 C5 

Can anyone please help me, how should i achieve result? 谁能帮我,我应该如何取得成果?

Assuming column names are C1, C2, C3, C4, C5. 假设列名称为C1,C2,C3,C4,C5。

Pseudo code/Algorithm. 伪代码/算法。

int C1_MaxValue, C2_MaxValue, C3_MaxValue, C4_MaxValue, C5_MaxValue;
string C1_Row, C2_Row, C3_Row, C4_Row, C5_Row;

//Initialize row1 values as max values.
C1_MaxValue = DataTable.Rows[1]["C1"];
C2_MaxValue = DataTable.Rows[1]["C2"];
C3_MaxValue = DataTable.Rows[1]["C3"];
C4_MaxValue = DataTable.Rows[1]["C4"];
C5_MaxValue = DataTable.Rows[1]["C5"];

//Set R1 as row for max values.
C1_Row = C2_Row = C3_Row = C4_Row = C5_Row = DataTable.Rows[1][Row1];

For (i=2 to RowCount -1)

 if(Datatable.Rows[i]["C1"] > C1_MaxValue) 
 {       
      C1_MaxValue = Datatable.Rows[i][C1]; 
      C1_Row = Datatable.Rows[i][0];
 }
 //Do the above for all other columns.
End For

At the end of this for the above variables should contain the max values and corresponding max rows. 最后,上述变量应包含最大值和相应的最大行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM