2016-03-01 62 views
-1

我每天在我的Elmah中看到這個錯誤。如何解決這個問題?輸入字符串格式不正確。在C#ASP.NET中

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 40:  { 
Line 41:   String Pass = password.Text; 
Line 42:   Int64 UserName = Convert.ToInt64(username.Text); 
Line 43: 
Line 44:   if (Convert.ToInt32(Session["FaildLoginTime"]) == 5) 

Source File: c:\Inetpub\vhosts\domin.com\my.domin.com\WebMaster\LoginMaster.master.cs Line: 42

Stack Trace:

[FormatException: Input string was not in a correct format.] 

    System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +11793873 

    System.Number.ParseInt64(String value, NumberStyles options, NumberFormatInfo numfmt) +133 

    System.Convert.ToInt64(String value) +51 

    WebMaster_LoginMaster.btnLogin_Click(Object sender, EventArgs e) in c:\Inetpub\vhosts\domin.com\my.domin.com\WebMaster\LoginMaster.master.cs:42 

    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9696694 

    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +204 

    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12 

    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15 

    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35 

    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639 
+1

您嘗試將字符串轉換爲Int64的,如果你試圖像KKK它會拋出一個異常... Convert.ToInt64(轉換)只包含數字的字符串工作。 –

+1

記錄'username.Text'的值...確保它不是空字符串或包含非數字字符。 – user1666620

回答

0

在第42行:Int64 UserName = Convert.ToInt64(username.Text);你應該確保username.Text返回一個有效的整數。