将新数据添加到 Access 数据库后,我似乎无法刷新 ComboBox。
这是我用来添加新数据的代码:
private void btnAddUser_Click(object sender, EventArgs e)
{
AccountForm actFrm = new AccountForm();
if (actFrm.ShowDialog() == DialogResult.OK)
{
try
{
this.oleDbDataAdapter1.InsertCommand.CommandText =
"INSERT INTO userTable (AccountName, Username, PopServer, PopPort, Psswrd, SmtpServer, SmtpPort, Email)" +
"VALUES ('" + actFrm.txtAccName.Text + "','" + actFrm.txtUsername.Text + "','" + actFrm.txtPop3.Text + "','" + actFrm.txtPop3Port.Text + "','" + actFrm.txtPassword.Text + "','" + actFrm.txtSmtp.Text + "','" + actFrm.txtSmtpPort.Text + "','" + actFrm.txtEmail.Text + "')";
//open the bridge between the application and the datasource
this.oleDbConnection1.Open();
this.oleDbDataAdapter1.InsertCommand.Connection = oleDbConnection1;
//execute the query
this.oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();
//close the connection
this.oleDbConnection1.Close();
MessageBox.Show("User Added Successfully"); //inform the user
//tried here to refresh and even open close the myConn connection. to no avail
}
catch (System.Data.OleDb.OleDbException exp)
{
//close the connection
this.oleDbConnection1.Close();
MessageBox.Show(exp.ToString());
}
}
}