【问题标题】:Input String Was Not Found In A Correct Format Error While Uploading Files上传文件时未找到格式正确的输入字符串错误
【发布时间】:2013-11-18 06:18:31
【问题描述】:

我试图在使用 ASP.NET 构建的网站中获得上传功能。但它一直给我这个错误 “/”应用程序中的服务器错误。

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

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

异常详情: System.FormatException:输入字符串格式不正确。

来源错误:

Line 43:lblDescription.Text = "Problem Description:";
Line 44:txtDescription.Text = dr["problem_desc"].ToString();
Line 45:this.lblFileName.Text = dal.GetFileName(ConstClass.ConnOLEDB, Convert.ToInt16(dr["problem"].ToString()));
Line 46:break;
Line 47:case "2": //Alter

源文件: C:\eteam\eteam.net - on\eteamuno\module_edit.aspx.cs 行:45

堆栈跟踪:

[FormatException: Input string was not in a correct format.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +12639413
   System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +224
   System.Int16.Parse(String s, NumberStyles style, NumberFormatInfo info) +41
   eteamuno.module_edit.editvalue() in C:\eteam\eteam.net - on\eteamuno\module_edit.aspx.cs:45
   eteamuno.module_edit.Page_Load(Object sender, EventArgs e) in C:\eteam\eteam.net - on\eteamuno\module_edit.aspx.cs:24
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
   System.Web.UI.Control.LoadRecursive() +71
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3064

谁能帮我解决这个问题?

【问题讨论】:

  • 显然dr["problem"] 不包含出现此异常时的数值。它包含什么?当遇到不包含有效数值的记录时,您希望系统如何响应?

标签: c# asp.net input syntax-error


【解决方案1】:

在将您的数字 String 转换为 numeric 时,而不是调用 Int16 调用 Int32 因为 Int16 是一个简短的。

Convert.ToInt32() -> 将字符串数字转换为整数。

替换这个:

this.lblFileName.Text = dal.GetFileName(ConstClass.ConnOLEDB, Convert.ToInt16(dr["problem"].ToString()));

以下:

this.lblFileName.Text = dal.GetFileName(ConstClass.ConnOLEDB, Convert.ToInt32(dr["problem"].ToString()));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-01
    相关资源
    最近更新 更多