gpt4 book ai didi

c# - db字段中值为0输出空

转载 作者:行者123 更新时间:2023-11-29 22:11:09 24 4
gpt4 key购买 nike

我使用 C# 和 MySQL 数据库中的 ASP.NET 4 工作。

在表 doTable 中,我有字段 pcs,数据类型为 int length 11

我需要更新表单中的此字段pcs

此字段pcs中的可能值为:0、> 0 或 null。

但是当我将字段pcs更新为后,为什么这个字段仍然是空的?

在数据库中,我的字段 pcs 为零,我认为问题出在 aspx 页面中。

我已经尝试过,但没有成功。

你能推荐一下吗?

提前谢谢您。

pcsDB = dr["pcs"] == DBNull.Value ? 0 : Convert.ToInt32(dr["pcs"]);

if (pcsDB > 0) {
pcs.Text = pcsDB.ToString();
pcs.Enabled = false;
} else {
pcs.Enabled = true;
}

最佳答案

试试这个:

pcsDB = dr["pcs"] == DBNull.Value ? -1 : Convert.ToInt32(dr["pcs"]);
if (pcsDB >= 0)
{
pcs.Text = pcsDB.ToString();
pcs.Enabled = false;
}
else
{
pcs.Enabled = true;
}

关于c# - db字段中值为0输出空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31654877/

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