【发布时间】:2018-08-19 17:42:31
【问题描述】:
这是我一直试图执行的逻辑,但它给出了问题:
protected void Price_Update_Click(object sender, EventArgs e)
{
decimal Price;
var gvr = (GridViewRow)(sender as Control).Parent.Parent;
int index = gvr.RowIndex;
var box1 = (TextBox)GridView1.Rows[index].Cells[4].FindControl("TextBox1");
bool prc = decimal.TryParse(box1.Text, out Price);
var PriceString = GridView1.Rows[index].Cells[4].Text.Replace(" AUD", "");
var btn = (Button)sender;
var row = (GridViewRow)btn.NamingContainer;
var ProductNo = row.Cells[0].Text;
var BranchNo = row.Cells[6].Text;
if (Price > 00.00)
{
var CS = "data source=LAPTOP-ODS96MIK\\MSSQL2014; database = Grocery_Demo; integrated security=SSPI";
var con = new SqlConnection(CS);
var cmd = new SqlCommand("UpdateProductQuantity", con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
con.Open();
cmd.Parameters.AddWithValue("@ProductPrice", Price);
cmd.Parameters.AddWithValue("@ProductNo", ProductNo);
cmd.Parameters.AddWithValue("@GroceryBranchNo", BranchNo);
cmd.ExecuteNonQuery();
con.Close();
MessageBox("Price has been updated");
DisplayProducts();
}
else if (Price == 00.00 || prc == false)
{
Label5.Text = "Please don't keep the price blank";
DisplayProducts();
}
}
我面临的问题是两个 if 条件下都有红线,它是说:
运算符“>”不能应用于“十进制”和“双精度”类型的操作数
我仍然无法弄清楚我错过了什么技巧。
如果提供适当的语法解决方案会很有帮助。
【问题讨论】:
-
Try Price > 0m m 表示十进制文字 Also Price == 0m
-
添加一个“m”,例如 0.00m 使其成为十进制
-
难以置信,我真的找不到
==运算符的重复项。虽然在这种情况下运算符的逻辑,可以转移到任何比较运算符。 -
我仍然认为this post 应该回答您的问题。如果我与您发布的错误消息有关