0

当我尝试在我的 Web 应用程序上运行报告时,我收到此错误:

“/Revenue”应用程序中的服务器错误。

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

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

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

源错误:

Line 219:        var ans = from a in analytics.Rows.Cast<DataRow>()
Line 220:                  group a by a["LineTitle"] into g
Line 221:                  select new                  
Line 222:                  {
Line 223:                      Name = g.Key.ToString(),

[FormatException: Input string was not in a correct format.]
   System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt) +10691639
   System.Double.Parse(String s) +23
   Main_Report.<CountryAnalytics>b__2e(IGrouping`2 g) in d:\vistaweb\Revenue\MainReport.aspx.cs:221
   System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +145
   System.Linq.Enumerable.Count(IEnumerable`1 source) +4125469
   ASP.mainreport_aspx.__DataBind__control28(Object sender, EventArgs e) in d:\vistaweb\Revenue\MainReport.aspx:303
   System.Web.UI.Control.OnDataBinding(EventArgs e) +92
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +85
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.Control.DataBindChildren() +187
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +94
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.WebControls.DataList.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +136
   System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean useDataSource) +484
   System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +63
   System.Web.UI.WebControls.BaseDataList.DataBind() +54
   Main_Report.Page_LoadComplete(Object sender, EventArgs e) in d:\vistaweb\Revenue\MainReport.aspx.cs:118
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Page.OnLoadComplete(EventArgs e) +9631466
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +765

文件中的代码如下所示:

   var ans = from a in analytics.Rows.Cast<DataRow>()
              group a by a["LineTitle"] into g
              select new                  
              {
                  Name = g.Key.ToString(),
                  SalesPersonStats = g.Key.ToString().Contains(SP.FullName),
                  Value = g.FirstOrDefault()["LinaValue"].ToString(),
                  Percentage = g.FirstOrDefault()["LinePercent"].ToString(),
                  Change = Math.Round(double.Parse(g.FirstOrDefault()["LinaValue"].ToString()) - double.Parse(g.LastOrDefault()["LinaValue"].ToString()), 2)
              };

知道为什么它说输入字符串的格式不正确 'select new' 吗?

谢谢

4

1 回答 1

1

可能,在此语句中从 double.Parse 引发异常:

Change = Math.Round(double.Parse(g.FirstOrDefault()["LinaValue"].ToString()) - double.Parse(g.LastOrDefault()["LinaValue"].ToString()), 2)

将 .ToList() 添加到 LINQ 语句的末尾,以便在绑定报告之前评估查询(并引发异常)。在那里你有机会调试格式。

于 2012-08-28T07:30:27.687 回答