【发布时间】:2016-11-19 19:58:03
【问题描述】:
我已经完成了我的项目,现在我只是面临一个小问题,我不知道如何解决问题是在 Form_Load 它从数据库中获取价值并在 Listbox 中显示它没关系,但它没有添加 @ 987654324@ 商品价格后请帮助我并告诉我如何添加这个。我正在使用这种编码:
txtDisplay.Text = "Return/" + "Receipt No:" + Return_Form.setalueforText011;
label1.Text = Return_Form.setalueforText011;
OleDbConnection VCON = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Restaurant.accdb");
DataSet dsa = new DataSet();
DataTable dt = new DataTable();
dsa.Tables.Add(dt);
OleDbDataAdapter da = new OleDbDataAdapter();
da = new OleDbDataAdapter("SELECT [Column1],[Column2],[Column3] from [Total] Where [Receipt No] = " + label1.Text + "", VCON);
da.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++)
{
// Create and initialize a new tblProduct from the datatable row
tblProduct current = new tblProduct();
current.productName = dt.Rows[i]["Column2"].ToString();
current.productPrice = Convert.ToDecimal(Math.Round(Convert.ToDecimal(dt.Rows[i]["Column1"].ToString())));
// Add to your list of products
products.Add(current);
// This line is wrong because you overwrite the value at each loop
label3.Text = dt.Rows[i]["Column3"].ToString();
// Sum the price of the current tblProduct
Total += (decimal)current.productPrice;
}
// Outside the loop update your total label
textBox59.Text = "Rs: " + String.Format("{0:}", Total+".00");
VCON.Close();
请告诉我如何在商品价格后添加 .00。
【问题讨论】:
-
你问了完全相同的问题here。这个问题有答案。如果您在应用 cmets 中的答案时遇到任何问题。