簡體   English   中英

事件未觸發

[英]Event isn't triggered

我創建了一個名為textBox1_Leave的事件; 但是當我運行我的程序時,我將焦點從txtBox1 ,事件不會被觸發。

我希望觸發此事件,因此我可以檢查用戶在txtBox1中輸入的NametxtBox1存在於我的數據庫中。 如果是,我想通過設置button1.Enable = true啟用button1 ,否則啟用false

我的C#代碼:

private void textBox1_Leave(object sender, EventArgs e)
{
    OleDbConnection A=new OleDbConnection();
    A.ConnectionString=Program.DBPATH;
    A.Open();

    OleDbCommand BB=new OleDbCommand();
    BB.Connection=A;
    BB.CommandText="SELECT username FROM Users WHERE (username = '" + textBox1.Text + "')";
    OleDbDataReader CC = BB.ExecuteReader();

    if (CC.Read())
    {
        button1.Enabled=true;
    }
    else
    {
        button1.Enabled=false;
    }
}
first check the event is wired up in constructor of the page

textBox1.Leave += textBox1_Leave;


and then

1) Debug the program and check whether break point is hitting.

我相信你正在開發Windows應用程序。 我建議你按照以下步驟操作:

1)調試程序並檢查斷點是否正在命中。

2)在你的表單上你應該有一些除文本框之外的控件,然后只有Leave事件才會觸發。 如果您在表單上只有文本框,則不會觸發文本框的Leave事件。

3)使用try catch block否則如果存在運行時錯誤,應用程序將崩潰。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM