私の目的は、現在のコンボボックスの値に応じてボタンをフレキシブルにすることですが、問題は、フリーズする特定のイベントでプログラムを実行するとき、シンタックスに何か問題がある、スロー?なぜフリーズしますか?
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(選択== "追加")_これはどのようにこの状態から抜け出すでしょうか? – TaW