我该如何循环遍历读取的
例如:1个汉堡有2个价格--$1和$2。遍历数据后,结果应该有2行相同的产品但价格不同。我该怎么做?以下是我的代码:
DataGridView
中的每一行? 在我的代码中,由于相同的productID,行不会绑定到下一行,因此DataGridView
不会移动到新行。它停留在同一行并覆盖价格(对于某些产品,我有两个价格)。我该如何循环遍历每一行,显示相同的productID但具有不同的价格?例如:1个汉堡有2个价格--$1和$2。遍历数据后,结果应该有2行相同的产品但价格不同。我该怎么做?以下是我的代码:
productID = odr["product_id"].ToString();
quantity = Double.Parse(odr["quantity"].ToString());
//processing data...
key = productID.ToString();
if (key != key_tmp)
{
//update index...
i++;
//updating variable(s)...
key_tmp = key;
}
if (datagridviews.Rows[i].Cells["qty"].Value != null) //already has value...
{
currJlh = Double.Parse(ddatagridviews.Rows[i].Cells["qty"].Value.ToString());
}
else //not yet has value...
{
currQty = 0;
}
currQty += qty;
//show data...
datagridviews.Rows[i].Cells["price"].Value = cv.toAccountingCurrency_en(Double.Parse(odr["item_price"].ToString()));
MessageBoxes.Show(i.ToString());
MessageBoxes.Show(datagridviews.Rows[i].Cells["price"].Value.ToString()); // in here there is two price that looped but won't showed in datagridviews