Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 3 inputs like 3 subject marks,I want Store totalmarks(float) and Averagemarks(float) in database.I am getting an error like above "Input string was not in a correct format".

Actually That Excat Code Line By Line Code Execute in my previous Example.

Now that previous Pgm I am Extended with Dropdownlist and gridview.But its not working present pgm.can any one Explain whats the problem,plz solve my issue As soon As possible..
Thanks in Advance

What I have tried:

float m1 =float.Parse(txtm1.Text);
float m2 = float.Parse(txtm2.Text);
float m3 = float.Parse(txtm3.Text);
float totmarks = m1 + m2 + m3;

//SAvgmarksarks
float Avgmarks = totmarks / 3;
Posted
Updated 20-Jun-18 21:49pm

 
Share this answer
 
Never assume that users will type the right data - always convert it using TryParse (or TryParseExact in some cases).
C#
float m1;
if (!float.TryParse(txtm1.Text, out m1))
   {
   ... report input error to user ...
   return;
   }
 
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