Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written code to do basic calculation to do percentage.


[CODE]

double mamount = Convert.ToDouble(DiversityPlan_ContractAmount.Text);
double mlamount = Convert.ToDouble(DiversityPlan_Amount.Text);
double msub = (mlamount / mamount) * 100;
DiversityPlan_MPRCNTAGE.Text = msub.ToString();
[/CODE]



The code does the calculation and show on the page perfect.

but when I go to save the data on the page to the database

it not saving the percentage that appears output textboxes to the database.

any ideas ??????????????
Posted

Well, for a start, your page will blow up if someone types a non number in to the textbox. Second, you showed us the code that works, and then asked us why the code you didn't show us, does not work. We don't know, we've not seen it.

double.TryParse is how you convert to double without blowing up on invalid input.
 
Share this answer
 
Comments
postonoh 22-Aug-10 13:15pm    
Thanks
postonoh 22-Aug-10 14:53pm    
The text boxes are set for numeric only. So if an user type anything that is not numeric it show an error on the side. The reason I showed you the code is because, it works and populate the necessary boxes when calculated. The problem I am having is when I place percentages in the boxes manually and save it write the information to the database. Yet when I have the press calculate button the percentage shows up in the proper textboxes, click the save button the percentage are there when I query the database. At first I thought it was because the percentage boxes set to readonly. change them to allow number to be entered and same results.
Looks like between you click the Calculate and Save button, the percentage value was set to empty. It means when you click the save button, the page doesn't maintain the percetage value.
 
Share this answer
 

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