日期:2014-05-18  浏览次数:20742 次

求大虾指教~
未处理的“System.FormatException”类型的异常出现在 mscorlib.dll 中。

其他信息: 输入字符串的格式不正确。

问题代码
 public DataRow drUpdate;

drUpdate = dataSet11.Tables["student"].Rows.Find(Int32.Parse(txtSNo.Text)); 

当跑到drUpdate时就会出问题

------解决方案--------------------
txtSNo.Text不能被转为int,格式不对
------解决方案--------------------
看错误应该是txtSNo.Text不是数字了。
------解决方案--------------------
FormatException 很明显格式不正确。
验证txtSNo.Text 只能输入数字
------解决方案--------------------
FormatException 很明显格式不正确。
验证txtSNo.Text 只能输入数字
加一个检查错误的
------解决方案--------------------
看看txtSNo.Text是不是整形类型的字符串
或者txtSNo.Text是否包含特殊字符。比如空格之类的
------解决方案--------------------
拆成两行写,然后在第一行设置断点,调试执行到这,观察 txtSNo.Text 值是否全是数字,如果是单步执行下去,看还有没异常
C# code
int key = Int32.Parse(txtSNo.Text);
drUpdate = dataSet11.Tables["student"].Rows.Find(key);