Paolo Duhaylungsod
Paolo Duhaylungsod

Reputation: 487

Input string was not in a correct format even i have the right values in it

i have a shopping cart website. however when i submit the "submit order button" its giving me an error saying that the input string was not in a correct format. below, i have the code where i declared the variables.

public class ShoppingCart
{
    public string CategoryName;
    public int CategoryID;
    public int ProductID;
    public int CustomerID;

    public string ProductName;
    public string ProductImage;
    public string ProductPrice;
    public string ProductDescription;
    public int ProductQuantity;

    public string BankDepositImage;

    public string CustomerName;
    public string CustomerEmailID;
    public string CustomerPhoneNo;
    public string CustomerAddress;
    public string ProductList;
    public string PaymentMethod;

    public string OrderStatus;
    public string OrderNo;

    public int TotalProducts;
    public int TotalPrice;
    public int StockType;
    public int Flag;

in this code are my textboxes.

ShoppingCart k = new ShoppingCart()
            {
                CustomerName = txtCustomerName.Text,
                CustomerEmailID = txtCustomerEmailID.Text,
                CustomerAddress = txtCustomerAddress.Text,
                CustomerPhoneNo = txtCustomerPhoneNo.Text,
                TotalProducts = Convert.ToInt32(txtTotalProducts.Text),
                TotalPrice = Convert.ToInt32(txtTotalPrice.Text),
                ProductList = productids,
                PaymentMethod = rblPaymentMethod.SelectedItem.Text

            };

i am receiving an error specifically in the shopping k = new shopping cart line of code. i am confused on what the problem is given that i am inputting the right value on each text box. please and thank you

Upvotes: 2

Views: 538

Answers (1)

Fᴀʀʜᴀɴ Aɴᴀᴍ
Fᴀʀʜᴀɴ Aɴᴀᴍ

Reputation: 6251

Try using Int32.Parse

TotalPrice = Int32.Parse(txtTotalProducts.Text) 

And as Steve suggests, make sure the input is devoid of decimals.

Upvotes: 2

Related Questions