本文介绍了C#Windows应用程序文本框输入事件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在尝试在文本框中输入以下代码,输入事件

Hi All,
I m trying to execute the following code in text box enter event

int id;
id = Convert.ToInt32(txtRollNumber.Text);
SqlConnection Con = new SqlConnection(@"Data Source=HORTON-2A5CB16E\SQLEXPRESS;Initial Catalog=Temp;Integrated Security=SSPI;Max Pool Size=100;Connect Timeout=1000");
Con.Open();


但在运行时它显示id = Convert.ToInt32(txtRollNumber.Text); input string is not in correct format
请帮忙

谢谢&问候
英德拉吉特

[添加了可读性的代码块]


but in run time it is showing id = Convert.ToInt32(txtRollNumber.Text); input string is not in correct format
Please help

Thanks & Regards
Indrajit

[added code block for readability]

推荐答案


int id = 0;
Int32.TryParse(txtRollNumber.Text, out id);



这篇关于C#Windows应用程序文本框输入事件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 15:25
查看更多