C# 如果更改列表视图中的记录值,如何更新列表视图以便查看所做的更改?

C# 如果更改列表视图中的记录值,如何更新列表视图以便查看所做的更改?,c#,sql,C#,Sql,这是我的更新代码,但在我更新listview中的记录后,我希望listview自动加载我所做的更改 private void ButtonUpdate_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(dblib.DatabaseConnection.GetConnectionString()); if (textBoxID.Text.Trim() == string.Empty

这是我的更新代码,但在我更新listview中的记录后,我希望listview自动加载我所做的更改

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();
}

当你这么做的时候,我可能建议您研究SQL注入的主题。您需要共享您必须在列表视图上填充数据源的代码,以便任何人都能提供正确的答案。如果您不是数据绑定,您只需在更新后执行与当前相同的查询来填充列表。您当前如何绑定数据源数据库查询的列表视图?