Npgsql.NpgsqlCommand.ExecuteReader C# (CSharp) Method

ExecuteReader() public method

Sends the CommandText to the Connection and builds a NpgsqlDataReader.
public ExecuteReader ( ) : Npgsql.NpgsqlDataReader
return Npgsql.NpgsqlDataReader
        public new NpgsqlDataReader ExecuteReader()
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "ExecuteReader");

            return ExecuteReader(CommandBehavior.Default);
        }

Same methods

NpgsqlCommand::ExecuteReader ( CommandBehavior cb ) : Npgsql.NpgsqlDataReader

Usage Example

Example #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