开发者

Input string was not in a correct format. even though data is similar, and same type

开发者 https://www.devze.com 2023-01-30 13:02 出处:网络
Alright so I changed the column that the As of Sales column gets its d开发者_开发问答ata from, however they are both the exact same type and look the exact same, but i still get this error.Both are De

Alright so I changed the column that the As of Sales column gets its d开发者_开发问答ata from, however they are both the exact same type and look the exact same, but i still get this error.Both are Decimal(38,6)

  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 60: <asp:TemplateField HeaderText="As Of Sales">
    Line 61: <ItemTemplate>
    Line 62:  <%#Getsales(Decimal.Parse(Eval("AsOFSales").ToString())).ToString("C0")%>
    Line 63: </ItemTemplate>
    Line 64: <FooterTemplate>


    Source File: C:\Documents and Settings\ChrisH\Desktop\AJAXEnabledWebSite4\Default2.aspx    Line: 62 

    Stack Trace: 


    [FormatException: Input string was not in a correct format.]
       System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +7471479
       System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt) +146
       System.Decimal.Parse(String s) +25
       ASP.default2_aspx.__DataBind__control17(Object sender, EventArgs e) in C:\Documents and Settings\ChrisH\Desktop\AJAXEnabledWebSite4\Default2.aspx:62
       System.Web.UI.Control.OnDataBinding(EventArgs e) +99
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +92
       System.Web.UI.Control.DataBind() +15
       System.Web.UI.Control.DataBindChildren() +211
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
       System.Web.UI.Control.DataBind() +15
       System.Web.UI.Control.DataBindChildren() +211
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
       System.Web.UI.Control.DataBind() +15
       System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +155
       System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +2417
       System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
       System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14
       System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
       System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
       System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
       System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
       System.Web.UI.WebControls.GridView.DataBind() +4
       Default2.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\ChrisH\Desktop\AJAXEnabledWebSite4\Default2.aspx.vb:106
       System.Web.UI.Control.OnLoad(EventArgs e) +99
       System.Web.UI.Control.LoadRecursive() +50
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627



"SELECT dbo.bSaleAsOfAdvancedMaster.SDESCR, dbo.bSaleAsOfAdvancedMaster.DYYYY, dbo.bSaleAsOfAdvancedMaster.AsOFNET, dbo.bSaleAsOfAdvancedMaster.ASOFPAX, dbo.bSaleAsOfAdvancedMaster.YENET, dbo.bSaleAsOfAdvancedMaster.YEPAX, dbo.b1SalesAsOfAdvanced.netSales, dbo.b1SalesAsOfAdvanced.PAX AS CurrentPAX FROM b1SalesAsOfAdvanced INNER JOIN bSaleAsOfAdvancedMaster ON dbo.bSaleAsOfAdvancedMaster.SDESCR = b1SalesAsOfAdvanced.SDESCR WHERE (bSaleAsOfAdvancedMaster.DYYYY =" & DropDownList1.SelectedValue & ") AND (b1SalesAsOfAdvanced.DYYYY = (year( getdate() ))) order by bSaleAsOfAdvancedMaster.SDESCR"


Check that you don't have any NULL values coming through. This might be causing the problem.

EDIT

Added in here as well, easier to read:

<%#Getsales(String.IsNullOrEmpty(Eval("AsOfSales").ToString()) ? 0 : Decimal.Parse(Eval("AsOFSales").ToString())).ToString("C0")%>


Check what are distinct values returned for "AsOfSales" column by the query. May be there is a value tht doesn't fall into numeric format.

0

精彩评论

暂无评论...
验证码 换一张
取 消