【发布时间】:2016-07-17 12:28:12
【问题描述】:
我的目标是根据组合框的当前值使我的按钮灵活,但问题是当我在特定事件上运行我的程序时,它会冻结,我的语法或我的计算机是否有问题只是慢?
private void cmbOperation_SelectedIndexChanged(object sender, EventArgs e)
{
string selected = (string)cmbOperation.SelectedItem;
while (selected == "ADD")
{
txtID.ReadOnly = true;
txtLName.ReadOnly = false;
txtFName.ReadOnly = false;
txtMI.ReadOnly = false;
txtGender.ReadOnly = false;
txtAge.ReadOnly = false;
txtContact.ReadOnly = false;
btnOperate.Text = "ADD CLIENT";
}
}
private void btnOperation_Clicked(object sender, EventArgs e)
{
if (cmbOperation.SelectedItem.Equals("ADD"))
{
string constring = "datasource=localhost;port3306;username=root";
string Query = "insert into mybusiness.client_list (LastName,FirstName,MI,Gender,Age,Contact) values('" + this.txtLName.Text + "','" + this.txtFName.Text + "','" + this.txtMI.Text + "','" + this.txtGender.Text + "','" + this.txtAge.Text + "','" + txtContact.Text + "' ;";
MySqlConnection conDB = new MySqlConnection(constring);
MySqlCommand cmDB = new MySqlCommand(Query, conDB);
MySqlDataReader myReader;
try
{
conDB.Open();
myReader = cmDB.ExecuteReader();
MessageBox.Show("Client Information has been added to the list");
while(myReader.Read())
{
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
【问题讨论】:
-
while (selected == "ADD") 它怎么会摆脱这种状况???
标签: c# button combobox click selectedindexchanged