title: UPDATE Records in a SQL Server Database through vb.net
body: <p>Hey Guy I need your help </p>
  
  <p>Im struggling on how to update any record in database sql server from vb.net</p>
  
  <p>First. I made a class in vb to put all the functions and to all them from the button UPDATE event i.e. to be more organised.</p>
  
  <p>I've managed to do all the coding for it (the update feature) perfectly, with no errors, but surprisingly, it does not update any field.</p>
  
  <p>PLEASE HELP   </p>
  
  <p>Here is my class where I make all the functions and call them from the button evens:</p>
  
  <pre><code> Public Function UpdateDataRecord(Command As String) As Integer
      Try
          SQLConnector.Open()
          SQLCommand = New SqlCommand(Command, SQLConnector)
  
  
          Dim ChangeCount As Integer = SQLCommand.ExecuteNonQuery()
  
          SQLConnector.Close()
  
          Return ChangeCount
      Catch ex As Exception
          MsgBox(ex.Message)
      End Try
  
      Return 0
  End Function
  </code></pre>
  
  <p>Here my update button even </p>
  
  <pre><code> Private Sub updateBtn_Click(sender As Object, e As EventArgs) Handles updateBtn.Click
  
      If IDTextBox.Text &lt;&gt; "" Then
          If (NameTextBox.Text.Length) &gt;= 3 Then
  
              Dim UpdateThisNow As String = "Update tblActivity " &amp;
                             "Set Name='" &amp; NameTextBox.Text &amp; "' " &amp;
                           "WHERE ID ='" &amp; IDTextBox.Text &amp; "' "
  
  
              If sqlcontrol.UpdateDataRecord(UpdateThisNow) = 0 Then
  
                  MsgBox("Not Found")
  
              Else
                  MsgBox("Successfully updated")
  
              End If
  
          Else
              MsgBox("Data Entered too short!")
          End If
  
      Else
          MsgBox("You must provide ID number")
  
      End If
  
  
  
  
  End Sub
  </code></pre>