输入字符串格式错误 [英] Input string Format err

查看:126
本文介绍了输入字符串格式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入字符串的格式不正确。

描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。



异常详细信息:System.FormatException:输入字符串的格式不正确。



来源错误:





第125行:// var amt = ob.SingleOrDefault(t => t.Planname == ddlexp.SelectedItem.Text);

第126行://会话[错误] = null;

第127行:list.Add(new CartItem(){Type =R,ProductName = ddlexp.SelectedItem.Text,Amount = Convert.ToDecimal(ddlexp.SelectedValue),visibility = true});

第128行:if(chkcover.Checked)

第129行:{

Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:


Line 125: //var amt = ob.SingleOrDefault(t => t.Planname == ddlexp.SelectedItem.Text);
Line 126: // Session["error"] = null;
Line 127: list.Add(new CartItem() { Type = "R", ProductName = ddlexp.SelectedItem.Text, Amount =Convert.ToDecimal(ddlexp.SelectedValue) , visibility = true });
Line 128: if (chkcover.Checked)
Line 129: {

推荐答案

输入字符串不在一个正确的格式。

表示它所说的:你传递给Convert.ToDecimal的字符串值无法识别为十进制数。



检查下拉列表的内容l ist,看看在调试器中返回了什么SelectedValue。
"Input string was not in a correct format."
Means what it says: the string value you are passing to Convert.ToDecimal is not recognisable as a Decimal number.

Check the content of the drop down list, and see what SelectedValue is returning in the debugger.


Convert.ToDecimal(ddlexp.SelectedValue)



这里选中的值是字符串格式,不能转换为十进制,确保它不是字符串格式


here the selected values is in string format which cannot be converted to decimal make sure that it is not in string format


这篇关于输入字符串格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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