title: Update selected row values in DataGridView through textbox using LINQ C#?
body: <p>I have a form. Which contains 2 tab. </p>
  
  <ol>
  <li>First Tab is for instance <code>Team1</code> info, where you can select player from <code>datagridview</code>. Selected player's info will populate in designated <code>textboxes</code>.</li>
  <li>In tab 2 <code>Team2</code>, and exactly same concept.</li>
  </ol>
  
  <p>I do use same exactly code to update Team 1(Tab1) player's info,and I works. But not for Team 2(Tab 2) player's.</p>
  
  <p>This is screen shot of my code[![enter image description here][1]][1]</p>
  
  <p>Team 1</p>
  
  <pre><code> private void updateButton_Click(object sender, EventArgs e)
      {
          //Local Variable
          int barID = 0;
  
  
          if (team1DataGridView.CurrentRow != null)
          {   
              //Get row index
              int rowIndex = team1DataGridView.CurrentRow.Index;
  
              //Pass to local Variable
              barID = Convert.ToInt32(team1DataGridView.Rows[rowIndex].Cells[0].Value);
          }
  
          var updatePlayers = (from p in _dbContext.barcelonaTeams
              where p.ID == barID
              select p).SingleOrDefault();
  
          if (updatePlayers != null)
          {
              updatePlayers.LastName = lastNameTextBox.Text;
              updatePlayers.FirstName = firstNameTextBox.Text;
              updatePlayers.Phone = cellNumberTextBox.Text;
              updatePlayers.PlayersPosition = playerPositionComboBox.Text;
          }
  
          try
          {
            //Submit Changes
             _dbContext.SubmitChanges();
  
              //Refresh datagridview'
              team1DataGridView.Refresh();
          }
          catch (Exception exception)
          {
              //Display an error message
              MessageBox.Show(exception.Message);
          }
      }
  </code></pre>
  
  <p>Team 2</p>
  
  <pre><code>private void mUpdateButton_Click(object sender, EventArgs e)
      {
          //Local variable
          int barID = 0;
  
  
          if (team2DataGridView.CurrentRow != null)
          {
              //Get row index
              int rowIndex = team2DataGridView.CurrentRow.Index;
  
              //Pass to local Variable
              barID = Convert.ToInt32(team2DataGridView.Rows[rowIndex].Cells[0].Value);
          }
  
          var updatePlayers = (from p in _dbContext.manchesterUnitedTeams
                               where p.ID == barID
                               select p).SingleOrDefault();
  
          if (updatePlayers != null)
          {
              updatePlayers.LastName = mLastNameTextBox.Text;
              updatePlayers.FirstName = mFirstNameTextBox.Text;
              updatePlayers.Phone = mCellNumberTextBox.Text;
              updatePlayers.PlayersPosition = mPositionComboBox.Text;
          }
          try
          {
              //Submit to datagridview
              _dbContext.SubmitChanges();
  
              //Refresh datagridview
              team2DataGridView.RefreshEdit();
          }
          catch (Exception exception)
          {
              //Show an error message
              MessageBox.Show(exception.Message);
          }
      }
  </code></pre>