从包含多个表的数据集中找到最小值和最大值
我正在开发一个 asp.net 应用程序,其中我有一个包含 3 个表的数据集,即 ds.Tables[0]、Tables[1] 和 Tables[2]
我需要找到最小数量和最大数量数据集的所有 3 个表。怎么做呢?
我在 SO 中发现了类似的问题在这里但不确定这将如何帮助我实现我的目标?
更新:
double minValue = double.MinValue;
double maxValue = double.MaxValue;
foreach (DataRow dr in dtSMPS.Rows)
{
double actualValue = dr.Field<double>("TOTAL_SUM"); // This fails specifying type cast error
minValue = Math.Min(minValue, actualValue);
maxValue = Math.Max(maxValue, actualValue);
}
请指导!谢谢。
I am developing an asp.net application where i have a dataset having 3 tables i.e. ds.Tables[0], Tables[1] and Tables[2]
I need to find minimum number and maximum number out of all the 3 tables of dataset. How to do that?
I found similar question in SO here but not sure how that would help me getting my way?
UPDATED:
double minValue = double.MinValue;
double maxValue = double.MaxValue;
foreach (DataRow dr in dtSMPS.Rows)
{
double actualValue = dr.Field<double>("TOTAL_SUM"); // This fails specifying type cast error
minValue = Math.Min(minValue, actualValue);
maxValue = Math.Max(maxValue, actualValue);
}
Please guide! Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用添加到已链接到的解决方案中的额外 for 循环。
IE
You could use an extra for loop added to the solution you have already linked to.
I.e.
如果它们具有相同的列名,假设为“decimalValue”,则:
If they have the same column name suppose 'decimalValue' then:
您可以使用 < 为每个数据表选择最小值和最大值每个 DataTable 上的 code>Compute 方法。
免责声明这不是安全代码;您应该检查错误、空值,并使其更具可读性。
像这样的东西应该有效:
you can select the min and max for each DataTable using the
Compute
method on each DataTable.Disclaimer this is not safe code; you should check for errors, nulls, and make it more readable.
Something like this should work: