gpt4 book ai didi

c# - 如何将来自数据库的数据更改为 DataGridView

转载 作者:太空狗 更新时间:2023-10-30 00:56:42 27 4
gpt4 key购买 nike

我有一个带有表 MASTER 的数据库。MASTER 有一个数据类型为 MONEY 的 Salary 列。现在,当我在 datagridview 中从数据库中获取数据时,我想用“Rs”显示货币列。附加到它。比如,如果数据库中的薪水是 100,我想将其视为 Rs。 100 在我的数据 GridView 中。Fill 方法只是将整个数据按原样复制到 datagridview 中。那怎么办呢?

最佳答案

dataGridView1.CellFormatting +=
new System.Windows.Forms.DataGridViewCellFormattingEventHandler(
this.dataGridView1_CellFormatting);

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (this.dataGridView1.Columns[e.ColumnIndex].Name == "Salary")
{
if (e.Value != null)
{
try
{
e.Value = String.Format("Rs. {0:F2}", e.Value);
e.FormattingApplied = true;
}
catch (FormatException)
{
e.FormattingApplied = false;
}
}
}
}

关于c# - 如何将来自数据库的数据更改为 DataGridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7030962/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com