public static bool Update_idEstadoPrestamo(int idPrestamoSeleccionado, int idNuevoEstado) { DbCommand comm = GenericDataAccess.CreateCommand(); comm.CommandText = "stp_xsarcprestamos_UPDATEIdEstado"; DbParameter param = comm.CreateParameter(); param.ParameterName = "@idPrestamo"; param.Value = idPrestamoSeleccionado; param.DbType = DbType.Int32; comm.Parameters.Add(param); param = comm.CreateParameter(); param.ParameterName = "@idNuevoEstado"; param.Value = idNuevoEstado; param.DbType = DbType.Int32; comm.Parameters.Add(param); param = comm.CreateParameter(); param.ParameterName = "@AffectedRows"; param.Value = 0; param.DbType = DbType.Int32; param.Direction = ParameterDirection.Output; comm.Parameters.Add(param); int success = -1; try { success = GenericDataAccess.ExecuteNonQuery(comm); } catch { //any errors are logged in GenericDataAccess... } return (success != -1); }
public static int ExecuteNonQuery(DbCommand command) { //the number of affected rows. int affectedRows = -1; //execute the command making sure the connection gets closed in the end. try { //open the connecction of the command command.Connection.Open(); //execute the command and get the number of affected rows. affectedRows = command.ExecuteNonQuery(); } catch (Exception ex) { //log eventual error and rethrow them. //Utilities.LogError(ex); MessageBox.Show(ex.Message, "Excepción Inexperada", MessageBoxButtons.OK, MessageBoxIcon.Information); throw ex; } finally { //close the connection command.Connection.Close(); } //return the number of affected rows. return affectedRows; }Thanks for your help!