使用c#在asp.net中输入字符串的格式不正确 [英] Input string was not in a correct format in asp.net using c#

查看:58
本文介绍了使用c#在asp.net中输入字符串的格式不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入字符串在asp.net中的格式不正确使用c#







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

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();

推荐答案

使用 Double.TryParse [ ^ ]而不是Double.Parse



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

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










double value = 0;
          double.TryParse(dr["star"]+"" , out value);
          lbl_avg.Text = Math.Round(value,1).ToString();


使用 TryParse 。如果字符串不是 double 类型,这将帮助您避免此错误。

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
}


这篇关于使用c#在asp.net中输入字符串的格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆