/// <summary> /// Exécute une requête de select et retour la première valeur /// de la première ligne. /// </summary> /// <param name="minRowsAffected">Nombre minimum de lignes affectées.</param> /// <param name="maxRowsAffected">Nombre maximum de lignes affectées.</param> /// <returns>Retourne la valeur ou null.</returns> public object ExecuteScalar(int minRowsAffected, int maxRowsAffected) { using (SqlServerDataReader reader = this.ExecuteReader()) { if (reader.Read()) { int rowsAffected = reader.RecordsAffected; if (rowsAffected > maxRowsAffected) { throw new SqlServerException(string.Format( CultureInfo.CurrentCulture, SR.ExceptionTooManyRowsAffected, rowsAffected)); } if (rowsAffected < minRowsAffected) { throw new SqlServerException(string.Format( CultureInfo.CurrentCulture, SR.ExceptionTooFewRowsAffected, rowsAffected)); } return(reader.GetValue(0)); } throw new SqlServerException(SR.ExceptionZeroRowAffected); } }
/// <summary> /// Execute l'insertion en base de la collection. /// </summary> /// <param name="commandName">Nom de la commande.</param> /// <param name="dataSourceName">Nom de la dataSource.</param> /// <returns>Liste d'objet insérés.</returns> public ICollection <T> ExecuteInsert(string commandName, string dataSourceName) { SqlServerCommand command = new SqlServerCommand(dataSourceName, commandName, _sbInsert.ToString()); CreateParameter(command); command.CommandTimeout = 0; BeanPropertyDescriptor primaryKey = _beanDefinition.PrimaryKey; using (SqlServerDataReader reader = command.ExecuteReader()) { while (reader.Read()) { T source = _index[reader.GetInt32(1).Value]; primaryKey.SetValue(source, reader.GetInt32(0).Value); } } return(_collection); }