我有form1,其中包含绑定到customer表的gridview,当用户双击gridview行时,会出现一个新的form2并允许用户修改数据。当用户修改数据并单击form2中的“保存”按钮时,它会保存对数据库的更改,但在form1重新打开之前,更改不会出现在form1 gridview中。为什么呢?
//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();
}