title: How Update cell in datagridview after enter? vb.net
body: <p>i want update value from datagridview to sql after enter on cell. but it don't work. </p>
  
  <p><strong>this code:</strong></p>
  
  <pre><code>Private Sub dgvShow_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles dgvShow.KeyPress
  
  Dim sb3 As New StringBuilder
  Dim da2 As New SqlDataAdapter
  
  For i As Integer = 0 To dgvShow.Rows.Count - 2
              If dgvShow.Rows(i).Cells(0).Value IsNot Nothing Then
                  sb3.Remove(0, sb3.Length())
                  sb3.Append("UPDATE PositionLevelWelfare ")
                  sb3.Append("SET wfDivision=@wfDivision,wfSection=@wfSection,wfPosition=@wfPosition,wfBaht=@wfBaht")
                  sb3.Append(" FROM PositionLevelWelfare pw")
                  sb3.Append(" WHERE pw.Run=@Run")
                  Dim SqlEdit As String = ""
                  SqlEdit = sb3.ToString()
  
                  da2.SelectCommand.CommandText = SqlEdit
                  da2.SelectCommand.Parameters.Add("@Run", SqlDbType.NVarChar).Value = dgvShow.Rows(i).Cells(0).Value
                  da2.SelectCommand.Parameters.Add("@wfDivision", SqlDbType.NVarChar).Value = dgvShow.Rows(i).Cells(1).Value
                  da2.SelectCommand.Parameters.Add("@wfSection", SqlDbType.NVarChar).Value = dgvShow.Rows(i).Cells(2).Value
                  da2.SelectCommand.Parameters.Add("@wfPosition", SqlDbType.NVarChar).Value = dgvShow.Rows(i).Cells(3).Value
                  da2.SelectCommand.Parameters.Add("@wfBaht", SqlDbType.NVarChar).Value = dgvShow.Rows(i).Cells(4).Value
                  da2.SelectCommand.ExecuteNonQuery()
                  da2.SelectCommand.Parameters.Clear() 
              End If
          Next
  End Sub
  </code></pre>
  
  <p>Thanks for tour time. :)</p>