Click here to Skip to main content
15,885,897 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Input string was not in a correct format in asp.net using c#



lbl_avg.Text = Math.Round(double.Parse(dr["star"].ToString()), 1).ToString();
Posted

use Double.TryParse[^] instead of Double.Parse

C#
dr["star"]  // should be having some null/empty or non numeric values.



C#
double value = 0;
          double.TryParse(dr["star"]+"" , out value);
          lbl_avg.Text = Math.Round(value,1).ToString();
 
Share this answer
 
v2
Comments
Prakash J 30-Apr-15 2:02am    
yes, empty value have
Prakash J 30-Apr-15 2:02am    
what can i do give example
Karthik_Mahalingam 30-Apr-15 2:15am    
check the updated solution
Use TryParse. This will help you avoid this error in case the string is not a double type.
if (Double.TryParse(dr["star"].ToString(), out result)) {
  //Do the conversion
}
 
Share this answer
 
Comments
Prakash J 30-Apr-15 2:14am    
can you change my above code using try parse
Abhinav S 30-Apr-15 2:32am    
Just replace Math.Round(double.Parse(dr["star"].ToString()), 1).ToString(); with the result value you get from TryParse.
Try it out.

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