Ejecutar una sentencia NO Select

2090 vistas

Usaremos el método ExecuteNonQuery del objeto Command.

Ejemplo con SQL Server



vbnet
  1. ' cadena de conexión
  2. Dim connectString As String = "database=derivatives;server=SRV01;User ID=samfisher;pwd=echelon"
  3. ' Objeto connection
  4. Dim connection As SqlConnection = new SqlConnection(connectString)
  5. ' obertura
  6. connection.Open()
  7. ' Objeto Command
  8. Dim command As SqlCommand = new SqlCommand("UPDATE usr_contract set ctr_n = ctr_n + 1", connection)
  9. ' ejecución
  10. Dim affectedrows As Integer = command.ExecuteNonQuery()
  11. Console.WriteLine("Número de filas afectadas {0}", affectedrows)
  12. ' cierre connection
  13. connection.Close()