这是我的更新代码,但是在对列表视图中的记录进行更新之后,我希望列表视图自动加载我所做的更改。
private void ButtonUpdate_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(dblib.DatabaseConnection.GetConnectionString());
if (textBoxID.Text.Trim() == string.Empty)
{
MessageBox.Show("Please enter values first.");
return;
}
string sql = "update PolicyHolder Set ";
sql += "Name='" + textBoxName.Text + "' ";
sql += ",Address='" + textBoxAddress.Text + "' ";
sql += ",Phone='" + textBoxPhone.Text + "' ";
sql += " Where ID ='" + textBoxID.Text + "' ";
textBoxID.Text = string.Empty;
textBoxName.Text = string.Empty;
textBoxAddress.Text = string.Empty;
textBoxPhone.Text = string.Empty;
MessageBox.Show("Update Success.");
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
}