c# - 为什么我的价格在更新后变成了 RM0.00?
问题描述
这是我的前端代码
我试图从 double 更改为 float 和 char 但同样的事情发生了。即使我更新数量,价格部分也会变为 0.00 。如何解决这个问题?
<td><asp:Label ID="lblPPrice" runat="server" Text='<%# Eval("PPrice","{0:c}")
%>' ></asp:Label>
<asp:TextBox ID="txtPPrice" runat="server" Text='<%# Eval("PPrice","
{0:c}") %>' Visible="false"></asp:TextBox> </td>
<td><asp:Label ID="lblPSelPrice" runat="server" Text='<%#
Eval("PSelPrice","{0:c}") %>' ></asp:Label>
<asp:TextBox ID="txtPSelPrice" runat="server" Text='<%#
Eval("PSelPrice","{0:c}") %>' Visible="false"></asp:TextBox> </td>
这是我背后的代码
cmd.Parameters.AddWithValue("@PPrice", SqlDbType.NVarChar).Value =
double.TryParse(productPrice, out money);
cmd.Parameters.AddWithValue("@PSelPrice", SqlDbType.NVarChar).Value=
double.TryParse(productSelPrice, out money);
解决方案
TryParse 方法返回布尔值。尝试分配货币变量。
if(double.TryParse(productPrice, out money))
{
cmd.Parameters.AddWithValue("@PPrice", SqlDbType.NVarChar).Value = money;
}
推荐阅读
- mysql - 为什么我不能用 Max date 加入这个查询?
- c# - 在 C# Web 应用程序中从命令提示符执行命令
- java - 无法在回收视图中获取文本
- xcode - 你如何通过 Mac 上的终端下载 SQLite for Xcode
- django - 当用户已经登录时,如何禁止用户进入注册页面?Django 2.1.2
- odoo - 如何在open erp中为每个产品添加唯一的项目代码
- ios - 使用 swift 在 iOS 上以编程方式创建热点
- go - 绑定到本地 IP 地址时的 i/o 超时
- hive - Hive - 每个日期选择不同的唯一 ID,无需创建外部表或使用 JOINS
- json - 在 mongoDB 中导入 json 文件时仅在 robomongo 中导入单个字段