本文介绍了数据类型转换错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,先生,

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.


即使我尝试了urObj.userid = int.Parse(txt_userid.Text).这也不起作用.

即使在数据库中,我也将useid声明为整数.

请帮助我....!!!!


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....!!!!

推荐答案



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!!!


这篇关于数据类型转换错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 09:44
查看更多