我有一个 form1,其中包含一个绑定到客户表的 gridview,当用户双击 gridview 行时,会显示一个新的 form2 并让用户修改数据。当用户修改数据并单击 form2 中的保存按钮时,它将更改保存到数据库,但更改不会出现在 form1 gridview 中,直到 form1 重新打开。为什么?
//FORM1 when user double click on rows to edit
private void radGridView1_CommandCellClick(object sender, EventArgs e)
{
GridCommandCellElement gCommand = (sender as GridCommandCellElement);
string v = gCommand.RowInfo.Cells["CustomerID"].Value.ToString();
Form2 f2 = new Form2(v);
f2.Show(this);
}
//FORM2 when user click on save button
private void button1_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(WindowsFormsApplication4TELERIK.Properties.Settings.Default.NorthwindConnectionString))
{
con.Open();
using (SqlTransaction tran =con.BeginTransaction(IsolationLevel.Serializable))
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "update customers set CompanyName='" + this.radTextBoxControl1.Text +"'";
tran.Commit();
cmd.ExecuteNonQuery();
}
}
this.Close();
}