本文介绍了条件日期的总和列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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");
更多推荐
条件日期的总和列
发布评论