实际上,当我单击 datagrid 视图的行或单元格时,它们会填充到文本框中进行编辑,在我编辑并点击更新后,如果我关闭并再次运行表单,datagridview 不会立即改变,它正在改变。我的要求是单击更新按钮后它应该立即更改。我用于更新点击的代码是:
private void btnUpdate_Click(object sender, EventArgs e)
{
SqlConnection con = Helper.getconnection();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
string PrjID = txtPrjID.Text;
string PrjName = txtPrjNmae.Text;
string Description = txtPrjdescription.Text;
string Date = txtPrjDate.Text;
string Size = txtPrjSize.Text;
string Manager = txtPrjManager.Text;
cmd.CommandText = "Update Projects set ProjectName= '" + PrjName + "', Description='" + Description + "', DateStarted='" + Date + "',TeamSize='" + Size + "',Manager='" + Manager + "' where ProjectID= " + PrjID + " ";
MessageBox.Show("Project Details are updated");
dataGridView2.Update();
dataGridView2.Refresh();
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
请告诉我我在做什么错误。