system.data.dll中发生了'system.stackoverflowexception'类型的未处理异常 [英] An unhandled exception of type 'system.stackoverflowexception' occurred in system.data.dll

查看:111
本文介绍了system.data.dll中发生了'system.stackoverflowexception'类型的未处理异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从关闭按钮关闭窗体后插入值,我用了,这个代码但是我有这个例外。



i知道什么是这个例外但是怎么样我使这段代码工作,



private void FRM_Main_FormClosing(对象发送者,FormClosingEventArgs e)



s =插入LoginAndOutDate(user_name,Logout_Date);

s = s +values(@ user_name,CURRENT_TIMESTAMP);



if(con .State == ConnectionState.Closed)

con.Open();



sCommand = new SqlCommand(s,con);

sCommand.Parameters.AddWithValue(@ user_name,textBox_ForName.Text);

sCommand.ExecuteNonQuery();



if(con.State == ConnectionState.Open)

con.Close();



this.Close(); < br $> b $ b

this.RefToFormLogin.Show();



}



我的尝试:



i当我从关闭按钮关闭表格时,值插入..

i want insert value after close the form from close button , i used , this code but i have this exception.

i know what is mean this exception but how i make this code work,

private void FRM_Main_FormClosing(object sender, FormClosingEventArgs e)

s = " insert into LoginAndOutDate(user_name, Logout_Date) ";
s = s + " values(@user_name, CURRENT_TIMESTAMP) ";

if (con.State == ConnectionState.Closed)
con.Open();

sCommand = new SqlCommand(s, con);
sCommand.Parameters.AddWithValue("@user_name", textBox_ForName.Text);
sCommand.ExecuteNonQuery();

if (con.State == ConnectionState.Open)
con.Close();

this.Close();

this.RefToFormLogin.Show();

}

What I have tried:

i want when i close form from close button , the value insert..

推荐答案

这是因为你在
this.Close();

中调用了

FRM_Main_FormClosing

,它再次触发了FRM_Main_FormClosing ......哪些调用this.Close()再次,....



结论:删除 this.Close()在你的FRM_Main_FormClosing事件处理程序。

which Triggers FRM_Main_FormClosing again ... which calls this.Close() again, ....

Conclution: Remove this.Close() in your FRM_Main_FormClosing Event handler.


这篇关于system.data.dll中发生了'system.stackoverflowexception'类型的未处理异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆