Click here to Skip to main content
16,012,116 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi sir,
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 29:             User_Registration urobj = new User_Registration();
Line 30:             urobj.Username = txt_username.Text;
Line 31:             urobj.Userid = Convert.ToInt32(txt_userid.Text);
Line 32:             urobj.Password = txt_passord.Text;
Line 33:             urobj.Conformpassword = txt_confrmpasswrd.Text;

Error At Line 31: Input string was not in a correct format.

even i tried urObj.userid=int.Parse(txt_userid.Text). This is also not working.

even in database also i declared useid as integer.

Please help me out....!!!!
Posted
Updated 10-Jan-12 11:10am
v2

The contents (text) in txt_userid contains illegal characters to be translated to integer. So ensure that you're inputting a proper number.

Also instead of using Parse, use TryParse[^] to check if the conversion can be done. If it cannot be done, inform the user to correct the data.
 
Share this answer
 
Comments
Abhinav S 10-Jan-12 23:29pm    
Of course. Try Parse is a good solution, I would have suggested that as well. 5.
Wendelius 11-Jan-12 0:51am    
Thanks Abhinav :)
Tech Code Freak 11-Jan-12 4:50am    
My 5!
Wendelius 11-Jan-12 11:27am    
Thanks :)
Prasad Guduri 5-Nov-12 7:30am    
Thank You....!!!!
Hi Prasad,

Even if you are passing empty string for text box txt_userid,
then also it will give same error.
So try your original code with some numeric value.
 
Share this answer
 
Comments
Prasad Guduri 5-Nov-12 7:30am    
Thank You....!!!!
Try this:

User_Registration urobj = new User_Registration();
urobj.Username = txt_username.Text;
if (txt_userid.Text!= null)
urobj.Userid = Convert.ToInt32(txt_userid.Text);
else
urobj.Userid = 0;

urobj.Password = txt_passord.Text;
urobj.Conformpassword = txt_confrmpasswrd.Text;

Alternatively,
Debug the line 31 and check the value for  txt_userid.Text.
If it is "" (blank) then do the following:

User_Registration urobj = new User_Registration();
urobj.Username = txt_username.Text;
if (txt_userid.Text!= "")
urobj.Userid = Convert.ToInt32(txt_userid.Text);
else
urobj.Userid = 0;

urobj.Password = txt_passord.Text;
urobj.Conformpassword = txt_confrmpasswrd.Text;


Hope this helps!!!
 
Share this answer
 
v2
Comments
Prasad Guduri 5-Nov-12 7:32am    
Really Nice Explanation...Thanks You Abnay...!!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900