3
我有這樣的方法。是否有可能textchanged事件只發生在文本框的重點?
public void CheckEmployee()
{
ConnectionStringSettings myConnectionString = ConfigurationManager.ConnectionStrings["LibrarySystem.Properties.Settings.LibraryConnectionString"];
using (SqlConnection myDatabaseConnection = new SqlConnection(myConnectionString.ConnectionString))
{
myDatabaseConnection.Open();
using (SqlCommand mySqlCommand = new SqlCommand("Select * from Employee where EmployeeID = '" + EmployeeIDtextBox.Text + "' ", myDatabaseConnection))
using (SqlDataReader sqlreader = mySqlCommand.ExecuteReader())
{
if (sqlreader.Read())
{
string EmployeeID = sqlreader.GetInt32(0).ToString();
string Name = sqlreader.GetString(1);
string Address = sqlreader.GetString(2);
EmployeeIDtextBox.Text = EmployeeID;
NametextBox.Text = Name;
AddresstextBox.Text = Address;
}
}
}
}
而且我必須寫這樣的代碼。
private void EmployeeIDtextBox_TextChanged(object sender, EventArgs e)
{
CheckBook();
NametextBox.Clear();
AddresstextBox.Clear();
}
private void NametextBox_TextChanged(object sender, EventArgs e)
{
CheckBook();
EmployeetextBox.Clear();
AddresstextBox.Clear();
}
問題是NametextBox_TextChanged也觸發當我在EmployeeIDtextBox輸入,因爲方法從數據庫中的值,並顯示它NametextBox。
NametextBox_TextChanged只有在關注NametextBox時纔可能發生?反之亦然。
謝謝:)
謝謝了! :) – 2013-05-13 04:42:04