条件日期的总和列

编程入门 行业动态 更新时间:2024-10-17 19:25:59
本文介绍了条件日期的总和列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Sum column where condition Date and

我的代码工作正常我需要在今天的日期时间添加条件......或者某些人... 一些帮助吗? 我尝试过什么:

My code working fine I need to add condition where datetime today...or somesthing... Some help? What I have tried:

double[] columnData = new double[mp_kasa_listaDataGridView.Rows.Count]; columnData = (from DataGridViewRow row in mp_kasa_listaDataGridView.Rows where row.Cells["dataGridViewTextBoxColumn16"].FormattedValue.ToString() != string.Empty select Convert.ToDouble(row.Cells["dataGridViewTextBoxColumn16"].FormattedValue)).ToArray(); textBox1.Text = columnData.Sum().ToString("#,0.00");

推荐答案

如果您需要添加更多应用于数据的条件,只需使用 && (和)运营商 所以类似于: If you need to add more conditions that are applied on the data , just use && (and) operator So something like: columnData = (from DataGridViewRow row in mp_kasa_listaDataGridView.Rows where row.Cells["dataGridViewTextBoxColumn16"].FormattedValue.ToString() != string.Empty && row.Cells["dataGridViewTextBoxColumn4"] == System.DateTime.Now.Date select Convert.ToDouble(row.Cells["dataGridViewTextBoxColumn16"].FormattedValue)).ToArray(); textBox1.Text = columnData.Sum().ToString("#,0.00");

根据您在网格中的数据,您可能需要转换列数据或使用日期范围等,因此上面的示例只是一个示例,而不是最终的解决方案。

Depending on the data you have in the grid, you may need to cast the column data or use date range and so on, so the above example is just an example, not a working final solution.

我已经回答了你的类似问题。 [ ^ ] 根据提供的想法,请检查: I already answered your similar question.[^] Based on the idea provided there, check this: DataTable dt = (DataTable)mp_kasa_listaDataGridView.DataSource; textBox1.Text = dt.AsEnumerable() .Where(x=>x.Field<DateTime>("date").Date==DateTime.Today) .Sum(x=>x.Field<double>("price")) .ToString("#,0.00");

更多推荐

条件日期的总和列

本文发布于:2023-11-21 23:32:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615104.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:总和   条件   日期

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!