錯誤出現在此代碼中。很久以前,當我試圖解決小數和整數這個問題時,我得到了同樣的錯誤。我該如何解決這個問題?總計十進制小數時出錯
protected void btnPlaceOrder_Click(object sender, EventArgs e)
{
string productids = string.Empty;
DataTable dt;
if (Session["MyCart"] != null)
{
dt = (DataTable)Session["MyCart"];
decimal totalPrice, totalProducts;
bool totalPriceConversionResult = decimal.TryParse(txtTotalPrice.Text, out totalPrice), totalProductsConversionResult = decimal.TryParse(txtTotalProducts.Text, out totalProducts);
ShoppingCart k = new ShoppingCart()
{
CustomerName = txtCustomerName.Text,
CustomerEmailID = txtCustomerEmailID.Text,
CustomerAddress = txtCustomerAddress.Text,
CustomerPhoneNo = txtCustomerPhoneNo.Text,
TotalProducts = totalProductsConversionResult ? totalProducts : 0,
TotalPrice = totalPriceConversionResult ? totalPrice : 0,
ProductList = productids,
PaymentMethod = rblPaymentMethod.SelectedItem.Text
};
DataTable dtResult = k.SaveCustomerDetails();
for (int i = 0; i < dt.Rows.Count; i++) // loop on how many products are added by the user
{
ShoppingCart SaveProducts = new ShoppingCart()
{
CustomerID = Convert.ToInt32(dtResult.Rows[0][0]),
ProductID = Convert.ToInt32(dt.Rows[i]["ProductID"]),
TotalProducts = Convert.ToInt32(dt.Rows[i]["ProductQuantity"]),
};
SaveProducts.SaveCustomerProducts();
}
Session.Clear();
GetMyCart();
lblTransactionNo.Text = "Your Transaction Number: " + dtResult.Rows[0][0];
pnlOrderPlaceSuccessfully.Visible = true;
pnlCheckOut.Visible = false;
pnlCategories.Visible = false;
pnlMyCart.Visible = false;
pnlEmptyCart.Visible = false;
pnlProducts.Visible = false;
SendOrderPlacedAlert(txtCustomerName.Text, txtCustomerEmailID.Text, Convert.ToString(dtResult.Rows[0][0]));
txtCustomerAddress.Text = string.Empty;
txtCustomerEmailID.Text = string.Empty;
txtCustomerName.Text = string.Empty;
txtCustomerPhoneNo.Text = string.Empty;
txtTotalPrice.Text = "0";
txtTotalProducts.Text = "0";
}
}
錯誤是不存在的行位置0 - 的購物SaveProducts =新購物車()
你能提供的錯誤? – Padraic
你收到了什麼錯誤?多一些信息,將不勝感激... – Saragis
還要注意,你正在談論'十進制',但你的代碼只使用'雙',據我所知。小數點會更合適。 –