插入文本框时出现错误,它显示错误无法将类型字符串隐式转换为Int
问题描述:
在BUSSINEES访问层:
IN BUSSINEES ACCESS LAYER:
#region "Variables"
protected int _uid =0;
protected string _name = "";
protected string _father = "";
public int _type = 0;
#endregion
#region "Properties"
public int Uid
{
get
{
return _uid;
}
IN Cs:
IN Cs :
BAL_insert Obj = new BAL_insert();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Obj.Uid = TextBox1.Text;
Obj.Name = TextBox2.Text;
Obj.Father = TextBox3.Text;
答
使用它..
Use it..
protected void Button1_Click(object sender, EventArgs e)
{
Obj.Uid = Convert.ToInt32(TextBox1.Text);
Obj.Name = TextBox2.Text;
Obj.Father = TextBox3.Text;
}
您将文本框字符串数据传递给整数Uid,这就是为什么会出现此错误
将Uid数据类型更改为字符串或将TextBox1.text转换为整数
you are passing Textbox string data into integer Uid that is why this error is coming
either change Uid datatype as string or convert you TextBox1.text to integer
protected string _uid =0;
...
...
public string Uid
{
get
{
return _uid;
}
不明显TextBox.Text的类型是字符串,而这不是int
?
请参阅:
https://msdn.microsoft.com/en-us/library/system.int32.tryparse%28v=vs.110%29.aspx [ ^ ],
https://msdn.microsoft.com/en-us/library/system.int32.parse%28v=vs.110%29.aspx [ ^ ]。-SA
Isn't that apparent that the type of TextBox.Text is string, and this is notint
?
Please see:
https://msdn.microsoft.com/en-us/library/system.int32.tryparse%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.int32.parse%28v=vs.110%29.aspx[^].—SA