实际上,当我单击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();
}
请告诉我我在做什么错误。