title: Update/Edit Database
body: <p>I know This is something simple yet I cannot do it right or find any answer searching google.</p>
  
  <p>I want to update/edit the data. in the database server, by clicking the data that display on my <code>DataGridView</code>.</p>
  
  <p>below is my sub Edit, the code is not automatically fetching the record to the textbox.</p>
  
  <pre><code>Private Sub btnEdit_Click(ByVal sender As System.Object, 
    ByVal e As System.EventArgs) Handles btnEdit.Click
  
    Dim transaction As SqlTransaction = Nothing
  
    With New SqlConnection(connectionString)
      Try
        Call .Open()
        transaction = .BeginTransaction()
        With .CreateCommand()
          .Transaction = transaction
          .CommandText = "UPDATE [tbl_info] SET [Name]=@Name WHERE [ID]=@ID;"
          With .Parameters
            .AddWithValue("ID", txtID.Text)
            .AddWithValue("Name", txtName.Text)
          End With
          Call .ExecuteNonQuery()
          Call transaction.Commit()
          Call MessageBox.Show("has been update successfully")
        End With
      Catch ex As Exception
        Call transaction.Rollback()
        Call MessageBox.Show(ex.Message, "Error")
      Finally
        Call .Close()
      End Try
    End With
    RefreshData()
  
    Call txtID.Clear()
    Call txtName.Clear()
  End Sub
  </code></pre>