title: Getting affected row count
body: <h2><strong>UPDATE 1:</strong></h2>
  
  <p>Does this look right?</p>
  
  <pre><code>Dim objSqlConnection As SqlConnection
  Dim objSqlCommand As SqlCommand
  
  Dim intAffectedRowCount As Integer
  
  Function update_function() As Integer
      Using objSqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("connectionString"))
          objSqlCommand = New SqlCommand("update table1 set col1 = @col1 where id = @id", objSqlConnection)
  
          objSqlCommand.Parameters.Add("@col1", SqlDbType.VarChar, 255).Value = strData
          objSqlCommand.Parameters.Add("@id", SqlDbType.Int, 4).Value = intID
  
          objSqlCommand.Connection.Open()
          intAffectedRowCount = objSqlCommand.ExecuteNonQuery()
          objSqlCommand.Connection.Close()
      End Using
  
      return intAffectedRowCount
  End Function
  </code></pre>
  
  <p>Does this close off everything opened properly?</p>
  
  <hr>
  
  <h2><strong>ORIGINAL QUESTION:</strong></h2>
  
  <p>I am currently using the following code to update a row in a database table:</p>
  
  <pre><code>objSQLConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("connString"))
  
  objSQLCommand = New SqlCommand("update table1 set col1 = @col1 where id = @id", objSQLConnection)
  
  objSQLCommand.Parameters.Add("@col1", SqlDbType.VarChar, 255).Value = strCol1Data
  objSQLCommand.Parameters.Add("@id", SqlDbType.Int, 4).Value = intID
  
  objSQLCommand.Connection.Open()
  objSQLCommand.ExecuteNonQuery()
  objSQLCommand.Connection.Close()
  </code></pre>
  
  <p>If I run that query in sql server, it returns a message saying "1 row affected".</p>
  
  <p>It's probably possible to access the same message from asp.net, but I don't know how to access it.</p>
  
  <p>Even if I get a count, i.e. 1.</p>
  
  <p>Anyone know how to get a count of the rows affected?</p>