i have a form with a comboBox, a textBox, and a button. the comboBox shows items from an sql database using dataBindingSources. after filling the textBox and clicking the button, a new item is added to this database, but i can't see this new item in the comboBox until i close and re-open the windowsForm. how to refresh the comboBox without close/re-open???
here's the code:
private void button2_Click(object sender, EventArgs e)
{
{
SqlConnection myConnection = new SqlConnection("****");
myConnection.Open();
try
{
SqlCommand myCommand = myConnection.CreateCommand();
myCommand.CommandText = "INSERT INTO Items (NameItem) " +
"Values ('" + textBox2.Text + "')";
myCommand.ExecuteNonQuery();
MessageBox.Show("Item Added", "OK");
}
catch (SqlException exp)
{
MessageBox.Show(exp.Message);
}
finally
{
myConnection.Close();
textBox2.Clear();
}
}