【发布时间】:2014-04-21 17:10:07
【问题描述】:
我想计算总价并将其显示在数据网格视图中。第四列没有从数据库中检索信息,所以我不知道该怎么做。下面是 GUI 的样子:
这是我到目前为止的代码......
double colTotal = 0; //set column total to 0
foreach (DataRow currentRow in itemDS.Tables[0].Rows)
{
// add to data grid view
invoiceDataGridView.Rows.Add(currentRow[1].ToString(), currentRow[2].ToString(), currentRow[3].ToString());
//Decalare variables for item quantity and price
var itemQuant = Convert.ToDouble(currentRow[1]);
var priceEach = Convert.ToDouble(currentRow[3]);
//Multiply the item quantity by the item price
double subTotal = itemQuant * priceEach;
//do this for each row
colTotal += subTotal;
}
//Display subtotal
subTotalOutput.Text = colTotal.ToString();
//Calculate tax
double tax = colTotal * .073;
//Display total tax
taxOutput.Text = Convert.ToString(tax);
//Add the subtotal and the total tax
double totPrice = colTotal + tax;
//Display total price
totalOutput.Text = Convert.ToString(totPrice);
}
【问题讨论】:
标签: c# database visual-studio-2010 ms-access