在做SqlDataAdapter.Update(DataSet)之前
加下面几句试试
GridView.EndEdit();
GridView.CurrentCell = Null;
DataSet.AcceptChanges();

解决方案 »

  1.   

    不行的加了DataSet.AcceptChanges();更保存不进数据库
      

  2.   

    代码是这样的
     //
            //添加数据在DataSet中添加新行
            //
            public void AddRow()
            {
                DataRow dr = this.ds.Tables[TableName].NewRow();
                //
                //新行插在汇总行的上面
                //
           //     int RowNum=this.ds.Tables [TableName ].Rows .Count ;
                this.ds.Tables[TableName].Rows.Add (dr);//.Add(dr);
            }  //
            //删除数据DataSet中删除
            //
            public void DeleteRow()
            {
                int RowIndex = this.dgv.CurrentCell.RowIndex;
               // MessageBox.Show(RowIndex.ToString());
              /*  if (RowIndex == this.dgv.Rows.Count - 1)
                {
                   // MessageBox.Show("汇总行不可删除", "系统提示");
                }*/
              //  MessageBox.Show(RowIndex.ToString());
                this.ds.Tables[TableName].Rows[RowIndex].Delete();
              //  MessageBox.Show(RowIndex.ToString());
                //
                //删除直接保存进数据库
                //
                this.SaveData();
            }//
            //保存数据
            //
            public void SaveData()
            {
                try
                {
                   /* this.dgv.CommitEdit(DataGridViewDataErrorContexts.Commit);
                    this.dgv.EndEdit();
                    this.bs.EndEdit();
                    this.da.Update(ds, TableName);*/
                    //
                    //莫行汇总不保存进数据库 ,所以在保存前将其删除
                    //
                 //   DeleteSum();
                  
                   // MessageBox.Show(RowNum.ToString());              /*   if (this.ds.HasChanges() == true)
                    {
                       
                    }*/
                   // this.ds .
                  //  this.ds.Tables[TableName].AcceptChanges();
                   
                  //  
                    this.dgv.CurrentCell = null;
                    this.dgv.CommitEdit(DataGridViewDataErrorContexts.Commit);
                    this.dgv.EndEdit();
                   
                    this.bs.EndEdit();
                   // this.dgv.Refresh();             //   this.ds.AcceptChanges();
                //   DataSet ds_temp = ds.GetChanges();
                 //   this.da.Update(ds_temp, TableName);
                   this.da.Update(ds, TableName);
                   // this.ds.AcceptChanges();
                    
                   // 
                    //this.da.Update(dv.Table );
                   
                }
                catch (Exception ex)
                {
                    Console.WriteLine("taskTown 保存数据时出错" + ex.Message.ToString());
                }        }
    如果进入界面不添加新数据,删除的信息可以保存进数据库添加新数据后就保存不进去了
    希望指点
      

  3.   

    先 da.Update(ds, TableName);
    再 ds.AcceptChanges();