日期:2014-05-19  浏览次数:20453 次

求救(那里出问题了)
我编一段更新代码,为何执行完后,数据库不能更新,
DataGrid1的可以更新,但是DataGrid2的更新不了,也不提示错误?代码如下:

private   void   Page_Load(object   sender,   System.EventArgs   e)
{
//   在此处放置用户代码以初始化页面
cn=new   SqlConnection(ConfigurationSettings.AppSettings[ "connStr "]);
if(!IsPostBack)  
BindGrid1();
BindGrid2();

}

#region   Web   窗体设计器生成的代码
override   protected   void   OnInit(EventArgs   e)
{
//
//   CODEGEN:   该调用是   ASP.NET   Web   窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

///   <summary>
///   设计器支持所需的方法   -   不要使用代码编辑器修改
///   此方法的内容。
///   </summary>
private   void   InitializeComponent()
{        
this.DataGrid1.PageIndexChanged   +=   new   System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
this.DataGrid1.CancelCommand   +=   new   System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_cancel);
this.DataGrid1.EditCommand   +=   new   System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_edit);
this.DataGrid1.UpdateCommand   +=   new   System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_update);
this.DataGrid1.DeleteCommand   +=   new   System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_delete);
this.DataGrid1.Load   +=   new   System.EventHandler(this.Page_Load);
this.DataGrid1.SelectedIndexChanged   +=   new   System.EventHandler(this.DataGrid1_SelectedIndexChanged);
this.DataGrid2.PageIndexChanged   +=   new   System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
this.DataGrid2.CancelCommand   +=   new   System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid2_cancel);
this.DataGrid2.EditCommand   +=   new   System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid2_edit);
this.DataGrid2.UpdateCommand   +=   new   System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid2_update);
this.DataGrid2.DeleteCommand   +=   new   System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid2_delete);
this.DataGrid2.Load   +=   new   System.EventHandler(this.Page_Load);
this.DataGrid2.SelectedIndexChanged   +=   new   System.EventHandler(this.DataGrid2_SelectedIndexChanged);
this.Button3.Click   +=   new   System.EventHandler(this.Button3_Click);
this.Load   +=   new   System.EventHandler(this.Page_Load);

}
#endregion

private   void   DataGrid1_PageIndexChanged(object   source,   System.Web.UI.WebControls.DataGridPageChangedEventArgs   e)
{
DataGrid1.CurrentPageIndex=e.NewPageIndex;
DataGrid2.CurrentPageIndex=e.NewPageIndex;
BindGrid1();
BindGrid2();
}
public   void   BindGrid1()
{       SqlDataAdapter   da   =   new   SqlDataAdapter( "select   *   from   Department ",cn);
DataSet   ds=new   DataSet();
da.Fill(ds);
DataGrid1.DataSource=ds;
DataGrid1.DataBind();

}
        public   void   BindGrid2()
&nb