title: I want to edit the datagridview to Update Dataset directly to DB,but always failed
body: <p>My Problem as follows;</p>
  
  <p>Last row of <code>datagridview</code> is always Focused, so when I click the <code>btnSave</code> of <code>toolStripButton</code>, I can not save the last row data to the database. How should I solve this problem? I know if I use the Button Control, I can solve this problem. But I want to know more:</p>
  
  <pre><code>private void btnSave_Click(object sender, EventArgs e)
              {
                  dgvHead.EndEdit();
                  dgvHead.RefreshEdit();
                  dgvHead.Refresh();
                  dgvHead.Update();
                  dgvHead.LostFocus += new EventHandler(dataGridView1_LostFocus);
                  //dgvHead.ClearSelection();
  
  
              //int id = 0;
              //保存到数据库之前先判断一下主表是否有重复记录
              string fno = txtfNo.Text.Trim();
              string fname = txtPname.Text.Trim();
              int orderqty = Convert.ToInt32(txtOrderQty.Text);
              double orderc = Convert.ToDouble(txtOrderCoefficient.Text);
              Image pic = pbchef.Image;
              //主表的修改
              string sql1 = "select count(1) from desProductAttach where fno='" + fno + "' and fno!='" + args["pNo"].ToString() + "' and fname='" + fname + "' and orderqty=" + orderqty + " and orderCoefficient=" + orderc + "";
              int count = Convert.ToInt32(SqlHelp.GetValue(CommandType.Text, sql1));
              if (count != 0)
              {
                  MessageBox.Show("数据库中已经存在重复记录,请修改后重新录入!");
                  return;
              }
              string sql2 = @"update desProductAttach set fno='" + fno + "',fname='" + fname + "',orderqty=" + orderqty + ",orderCoefficient=" + orderc + " where id="+id+"";
              SqlHelp.ExecuteNonQuery(CommandType.Text,sql2);
  
             //子表的更新(通过数据源更新)
              if (ds1.HasChanges())
              {
                  SqlCommandBuilder cb = new SqlCommandBuilder(sda1);
                  sda1.Update(ds1.Tables[0]);
                  ds1.AcceptChanges();
                 // dgvHead.Update();
                  MessageBox.Show("保存成功");
                 // ischange = false;
              }
  
          }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/lpDax.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lpDax.png" alt="Sample"></a></p>