private void SaveChg_Click(object sender, System.EventArgs e) 

try 

int row=this.UpdStuGrdDg.CurrentCell.RowNumber; 
this.UpdStuGrdDg.CurrentCell=new DataGridCell(row+1,0); 
if(UpdClassStudset.HasChanges())//如果改动是在根据乡镇检索的结果集上进行的那么,更改该结果集 

UpdSconn=new SqlConnection(UpdStuconnstr); 
UpdStuGrdsqlda=new SqlDataAdapter(this.UpdStustrconnClass,this.UpdSconn); 
SqlComm=new SqlCommandBuilder(UpdStuGrdsqlda); 
                  // SqlComm = new SqlDataAdapter 
                  // SqlDataAda = new SqlDataAdapter(UpdStuGrdsqlda); 
this.UpdStuGrdsqlda.Update(this.UpdClassStudset.GetChanges(),"HuZhu"); 
MessageBox.Show("保存修改成功!","信息"); 

else if(UpdNameStudset.HasChanges())//如果改动是在根据户主姓名检索的结果集上进行的那么,更改该结果集 

UpdSconn=new SqlConnection(UpdStuconnstr); 
UpdStuGrdsqlda=new SqlDataAdapter(this.UpdStustrconnName,UpdSconn); 
SqlComm=new SqlCommandBuilder(UpdStuGrdsqlda); 
UpdStuGrdsqlda.Update(this.UpdNameStudset.GetChanges(),"HuZhu"); 
MessageBox.Show("保存修改成功!","信息"); 


catch(Exception ex) 

MessageBox.Show(ex.ToString(),"信息"); 


//删除户主记录 
private void DelRecord_Click(object sender, System.EventArgs e) 

int rowNumber=this.UpdStuGrdDg.CurrentCell.RowNumber; 
try 

this.UpdClassStudset.Tables[0].Rows[rowNumber].Delete(); 
this.UpdNameStudset.Tables[0].Rows[rowNumber].Delete(); 
UpdSconn=new SqlConnection(UpdStuconnstr); 
UpdStuGrdsqlda=new SqlDataAdapter("",UpdSconn); 
SqlComm=new SqlCommandBuilder(UpdStuGrdsqlda); 
UpdStuGrdsqlda.Update(this.UpdNameStudset.GetChanges(),"HuZhu"); 
                UpdStuGrdsqlda.Update(this.UpdClassStudset.GetChanges(), "HuZhu"); 
MessageBox.Show("删除成功!","信息"); 

catch(Exception ex) 

MessageBox.Show(ex.ToString(),"信息"); } 
}         private void UpdateStu_Load() 
        {         }

解决方案 »

  1.   

    e.Message.ToString();这样错误详细点。
      

  2.   

    保存修改和删除记录操作不了,运行到红色那句,就直接跳到绿色的那段。然后看那个表的内容,就跟原来的一样,没有修改成功,也不能删除!
    private void SaveChg_Click(object sender, System.EventArgs e) 

    try 

    int row=this.UpdStuGrdDg.CurrentCell.RowNumber; 
    this.UpdStuGrdDg.CurrentCell=new DataGridCell(row+1,0); 
    if(UpdClassStudset.HasChanges())//如果改动是在根据乡镇检索的结果集上进行的那么,更改该结果集 

    UpdSconn=new SqlConnection(UpdStuconnstr); 
    UpdStuGrdsqlda=new SqlDataAdapter(this.UpdStustrconnClass,this.UpdSconn); 
    SqlComm=new SqlCommandBuilder(UpdStuGrdsqlda); 
                      // SqlComm = new SqlDataAdapter 
                      // SqlDataAda = new SqlDataAdapter(UpdStuGrdsqlda); 
    this.UpdStuGrdsqlda.Update(this.UpdClassStudset.GetChanges(),"HuZhu"); 
    MessageBox.Show("保存修改成功!","信息"); 

    else if(UpdNameStudset.HasChanges())//如果改动是在根据户主姓名检索的结果集上进行的那么,更改该结果集 

    UpdSconn=new SqlConnection(UpdStuconnstr); 
    UpdStuGrdsqlda=new SqlDataAdapter(this.UpdStustrconnName,UpdSconn); 
    SqlComm=new SqlCommandBuilder(UpdStuGrdsqlda); 
    UpdStuGrdsqlda.Update(this.UpdNameStudset.GetChanges(),"HuZhu"); 
    MessageBox.Show("保存修改成功!","信息"); 


    catch(Exception ex) 

    MessageBox.Show(ex.ToString(),"信息"); 


    //删除户主记录 
    private void DelRecord_Click(object sender, System.EventArgs e) 

    int rowNumber=this.UpdStuGrdDg.CurrentCell.RowNumber; 
    try 

    this.UpdClassStudset.Tables[0].Rows[rowNumber].Delete(); 
    this.UpdNameStudset.Tables[0].Rows[rowNumber].Delete(); 
    UpdSconn=new SqlConnection(UpdStuconnstr); 
    UpdStuGrdsqlda=new SqlDataAdapter("",UpdSconn); 
    SqlComm=new SqlCommandBuilder(UpdStuGrdsqlda); 
    UpdStuGrdsqlda.Update(this.UpdNameStudset.GetChanges(),"HuZhu"); 
                    UpdStuGrdsqlda.Update(this.UpdClassStudset.GetChanges(), "HuZhu"); 
    MessageBox.Show("删除成功!","信息"); 

    catch(Exception ex) 

    MessageBox.Show(ex.ToString(),"信息"); } 
    }         private void UpdateStu_Load() 
            {         }
      

  3.   

    保存修改和删除记录操作不了,运行到红色那句,就直接跳到绿色的那段。然后看那个表的内容,就跟原来的一样,没有修改成功,也不能删除!
    private void SaveChg_Click(object sender, System.EventArgs e) 

    try 

    int row=this.UpdStuGrdDg.CurrentCell.RowNumber; 
    this.UpdStuGrdDg.CurrentCell=new DataGridCell(row+1,0); 
    if(UpdClassStudset.HasChanges())//如果改动是在根据乡镇检索的结果集上进行的那么,更改该结果集 

    UpdSconn=new SqlConnection(UpdStuconnstr); 
    UpdStuGrdsqlda=new SqlDataAdapter(this.UpdStustrconnClass,this.UpdSconn); 
    SqlComm=new SqlCommandBuilder(UpdStuGrdsqlda); 
                      // SqlComm = new SqlDataAdapter 
                      // SqlDataAda = new SqlDataAdapter(UpdStuGrdsqlda); 
    this.UpdStuGrdsqlda.Update(this.UpdClassStudset.GetChanges(),"HuZhu"); 
    MessageBox.Show("保存修改成功!","信息"); 

    else if(UpdNameStudset.HasChanges())//如果改动是在根据户主姓名检索的结果集上进行的那么,更改该结果集 

    UpdSconn=new SqlConnection(UpdStuconnstr); 
    UpdStuGrdsqlda=new SqlDataAdapter(this.UpdStustrconnName,UpdSconn); 
    SqlComm=new SqlCommandBuilder(UpdStuGrdsqlda); 
    UpdStuGrdsqlda.Update(this.UpdNameStudset.GetChanges(),"HuZhu"); 
    MessageBox.Show("保存修改成功!","信息"); 


    catch(Exception ex) 

    MessageBox.Show(ex.ToString(),"信息"); 


    //删除户主记录 
    private void DelRecord_Click(object sender, System.EventArgs e) 

    int rowNumber=this.UpdStuGrdDg.CurrentCell.RowNumber; 
    try 

    this.UpdClassStudset.Tables[0].Rows[rowNumber].Delete(); 
    this.UpdNameStudset.Tables[0].Rows[rowNumber].Delete(); 
    UpdSconn=new SqlConnection(UpdStuconnstr); 
    UpdStuGrdsqlda=new SqlDataAdapter("",UpdSconn); 
    SqlComm=new SqlCommandBuilder(UpdStuGrdsqlda); 
    UpdStuGrdsqlda.Update(this.UpdNameStudset.GetChanges(),"HuZhu"); 
                    UpdStuGrdsqlda.Update(this.UpdClassStudset.GetChanges(), "HuZhu"); 
    MessageBox.Show("删除成功!","信息"); 

    catch(Exception ex) 

    MessageBox.Show(ex.ToString(),"信息"); } 
    }         private void UpdateStu_Load() 
            {         }
      

  4.   

    private void SaveChg_Click(object sender, System.EventArgs e) 

    try 

    int row=this.UpdStuGrdDg.CurrentCell.RowNumber; 
    this.UpdStuGrdDg.CurrentCell=new DataGridCell(row+1,0); 
    if(UpdClassStudset.HasChanges())//如果改动是在根据乡镇检索的结果集上进行的那么,更改该结果集 

    UpdSconn=new SqlConnection(UpdStuconnstr); 
    UpdStuGrdsqlda=new SqlDataAdapter(this.UpdStustrconnClass,this.UpdSconn); 
    SqlComm=new SqlCommandBuilder(UpdStuGrdsqlda); 
    //不应该是拿新创建的一个Adpter来更新对UpdClassStudset的更改。
    应该谁填充了UpdClassStudset 就拿那个Adpter来更新.

    this.UpdStuGrdsqlda.Update(this.UpdClassStudset.GetChanges(),"HuZhu"); 
    MessageBox.Show("保存修改成功!","信息"); 

    else if(UpdNameStudset.HasChanges())//如果改动是在根据户主姓名检索的结果集上进行的那么,更改该结果集 

    UpdSconn=new SqlConnection(UpdStuconnstr); 
    UpdStuGrdsqlda=new SqlDataAdapter(this.UpdStustrconnName,UpdSconn); 
    SqlComm=new SqlCommandBuilder(UpdStuGrdsqlda); 
    UpdStuGrdsqlda.Update(this.UpdNameStudset.GetChanges(),"HuZhu"); 
    MessageBox.Show("保存修改成功!","信息"); 


    catch(Exception ex) 

    MessageBox.Show(ex.ToString(),"信息"); 


    //删除户主记录 
    private void DelRecord_Click(object sender, System.EventArgs e) 

    int rowNumber=this.UpdStuGrdDg.CurrentCell.RowNumber; 
    try 

    this.UpdClassStudset.Tables[0].Rows[rowNumber].Delete(); 
    this.UpdNameStudset.Tables[0].Rows[rowNumber].Delete(); 
    UpdSconn=new SqlConnection(UpdStuconnstr); 
    UpdStuGrdsqlda=new SqlDataAdapter("",UpdSconn); 
    SqlComm=new SqlCommandBuilder(UpdStuGrdsqlda); 
    UpdStuGrdsqlda.Update(this.UpdNameStudset.GetChanges(),"HuZhu"); 
                    UpdStuGrdsqlda.Update(this.UpdClassStudset.GetChanges(), "HuZhu"); 
    MessageBox.Show("删除成功!","信息"); 

    catch(Exception ex) 

    MessageBox.Show(ex.ToString(),"信息"); } }