Click here to Skip to main content
15,900,254 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am working in entity framework 4.0 i got the error is string was not in correct format in my code.i applied all the thing that solve the problem but i could not. So can anyone please help me to solve this problem.
below is my code and i pointed where is error show.
C#
public void vatcalculation()
{
    valueentry();
     if (Convert.ToString(Taxtype) == "Taxable")     
    {
        if (Convert.ToString(onmrp) == "Y" && Convert.ToString(taxinex) == "N")
        {
            if (Convert.ToString(onsurcharge) == "VatAmount")
            {
                TAmount = Convert.ToDouble(txt_Tamount.Text.ToString());
                double v1 = (Vatper / 100) + 1;
                double App = ((quantity + free) * MRP) / v1;
                VatAmt = (App * Vatper) / 100;
                double surchargeamt = (VatAmt * surpercent) / 100;
                double totalamount = VatAmt + TAmount + surchargeamt;
                txt_surcharge.Text = surchargeamt.ToString();
                txt_Vat_Amount.Text = VatAmt.ToString();
                txt_Tamount.Text = totalamount.ToString();
                Discount();
                Disamt();
                price();
            }
            else if (Convert.ToString(onsurcharge) == "taxableAmt")
            {
            }

        }
        else if (Convert.ToString(onmrp) == "Y" && Convert.ToString(taxinex) == "Y")
        {
               TAmount = Convert.ToDouble(txt_Tamount.Text.ToString());
                 VatAmt = ((quantity + free) * MRP * Vatper) / 100;
                double surchargeamt = (VatAmt * surpercent) / 100;
                double totalamount = VatAmt + TAmount + surchargeamt;
                txt_surcharge.Text = surchargeamt.ToString();
                txt_Vat_Amount.Text = VatAmt.ToString();
                txt_Tamount.Text = totalamount.ToString();
                Discount();
                Disamt();
           }
    }
    else if (Convert.ToString(Taxtype) == "Taxfree")
    {
            double v1 = (Vatper / 100) + 1;                    // taxfree
            double app = (quantity * MRP) / v1;
            VatAmt = (app * Vatper) / 100;
            txt_Vat_Amount.Text = VatAmt.ToString();
      }
    }



 protected void ddl_Batch_No_SelectedIndexChanged(object sender, EventArgs e)
    {
        valueentry();
        //price();

        int j = Convert.ToInt32(ddl_Batch_No.SelectedItem.Value);
        var dd = from t in ae.Vats where t.Vat_Id == j select t;
        var ee = dd.First();
        Vatper = Convert.ToDouble(ee.Vat_Per);
        surpercent = Convert.ToDouble(ee.Surcharge_Per);
        onsurcharge = Convert.ToDouble(ee.On_Surcharge);//  error

        vatcalculation();
Posted
Updated 9-Dec-15 23:17pm
v4
Comments
F-ES Sitecore 10-Dec-15 5:22am    
ee.On_Surcharge can't be converted to double. Remember we can't run your code so we don't know what type On_Surcharge is or what it contains, but whatever it contains can't be converted to Double. Use double.TryParse instead so you can handle it when your data can't be converted.
ZurdoDev 10-Dec-15 9:08am    
This is a very easy problem to solve. But you'll have to debug it. For example, perhaps you are trying to convert a string to a date and the string is "bob." That clearly cannot convert to a date and so you'll get that error. All you have to do is debug the code, see what the values of your variables and controls are and you'll solve this on your own within a few minutes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900