如果我更改列表视图中的记录值,如何更新列表视图,以便可以看到所做的更改?

时间:2018-08-21 14:08:57

标签: c# sql

这是我的更新代码,但是在对列表视图中的记录进行更新之后,我希望列表视图自动加载我所做的更改。

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

0 个答案:

没有答案