c# - 如何从数据库中的列中计算字符长度并将它们放入 datagridview 中显示的新列中
问题描述
基本上,我有一个数据库,其中包含一个名为 anuncios 的表,其中包含以下列:
idAnnouncements | title | message | idClients (foreign key)|
,并且我有另一个名为 detalhefatura 的表,其中包含以下列:
idAnnouncements | idFatura (foreign key) | subTotal
在 C# 中:当我单击一个按钮时,我想计算 Announcements 表中消息列中的字母,并将它们放入列 subTotal 中,像这样
是需要查询还是只需要 C# 代码?
这就是我得到的,在上面打印屏幕中看到的标签中,具有相同 ClientID 的所有字符的数量
private void button1_Click(object sender, EventArgs e)
{
{
var linhas = dataGridView.Rows.Cast<DataGridViewRow>().Select(r => Convert.ToString(r.Cells["mensagem"].Value));
double somaLinhas = linhas.Sum(r => r.Length * 0.02);
lbltotal.Text = string.Format(@"{0:#,##0.00}", somaLinhas);
}
}
解决方案
columnSize = (Int32)cmd.ExecuteScalar();
在这之后:
dataGridView1.Rows[rowIndex].Cells[columnIndex].Value = columnSize;
推荐阅读
- node.js - How to join 2 collections in mongoose using nodejs
- javascript - 在页面加载时隐藏 tbody,永久显示广告组,使用 jQuery 在下拉选择中显示 tbody
- python - 显示来自数据库 Django 的复选框值
- c++ - 比如,虚函数我们可以在 C++ 中创建一个虚拟变量吗
- python - 仅在python中的双引号后拆分字符串
- c# - SelectedRow 计数在一种方法上始终等于 0,但在另一种方法上工作正常
- javascript - 将 console.log 重置为默认功能
- postgresql - 使用 postgres 从 jsonb 数组中删除元素
- elasticsearch - Elasticsearch 查询良好的标题关键字结果
- ios - 在 Swift 中使用命名资产初始化 URL() 的正确方法?