Npgsql.NpgsqlCommand.ExecuteReader C# (CSharp) Method

ExecuteReader() public method

Sends the CommandText to the Connection and builds a NpgsqlDataReader using one of the CommandBehavior values.
Currently the CommandBehavior parameter is ignored.
public ExecuteReader ( CommandBehavior cb ) : Npgsql.NpgsqlDataReader
cb CommandBehavior One of the CommandBehavior values.
return Npgsql.NpgsqlDataReader
        public new NpgsqlDataReader ExecuteReader(CommandBehavior cb)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "ExecuteReader", cb);

            // Close connection if requested even when there is an error.

            try
            {
                if (connection != null)
                {
                    if (connection.PreloadReader)
                    {
                        //Adjust behaviour so source reader is sequential access - for speed - and doesn't close the connection - or it'll do so at the wrong time.
                        CommandBehavior adjusted = (cb | CommandBehavior.SequentialAccess) & ~CommandBehavior.CloseConnection;

                        return new CachingDataReader(GetReader(adjusted), cb);
                    }
                }

                return GetReader(cb);
            }
            catch (Exception)
            {
                if ((cb & CommandBehavior.CloseConnection) == CommandBehavior.CloseConnection)
                {
                    connection.Close();
                }

                throw;
            }
        }

Same methods

NpgsqlCommand::ExecuteReader ( ) : Npgsql.NpgsqlDataReader

Usage Example

Beispiel #1
40
       public List<Product> getList()
       {
           using (NpgsqlConnection connection = getConnection())
           {
               using (NpgsqlCommand cmd = new NpgsqlCommand(SELECT_CMD, connection))
               {
                   connection.Open();
                   List<Product> result = new List<Product>();
                   using (var reader = cmd.ExecuteReader())
                   {
                       while (reader.Read())
                       {
                           Product temp = new Product();
                           temp.id = reader.GetGuid(0);
                           temp.description = reader.GetString(1);
                           temp.productGroupID = reader.GetGuid(2);
                           temp.Unit = Units.FromName(reader.GetString(3));

                           if (!reader.IsDBNull(4))
                           {
                               temp.weight = (Decimal)reader.GetFloat(4);
                           }

                           temp.money = reader.GetDecimal(5);
                           temp.quantity = reader.GetInt32(6);
                           result.Add(temp);
                       }
                   }

                   return result;
               }
           }
       }
All Usage Examples Of Npgsql.NpgsqlCommand::ExecuteReader