OleDbDataReader.GetValues(Object[]) Method

Definition

Populates an array of objects with the column values of the current row.

C#
public override int GetValues(object[] values);
C#
public int GetValues(object[] values);

Parameters

values
Object[]

An array of Object into which to copy the attribute columns.

Returns

The number of instances of Object in the array.

Implements

Examples

C#
using System;
using System.Data;
using System.Data.OleDb;

class Class1 {
   public static void Main() {
      using (OleDbConnection connection =
         new OleDbConnection("Provider=SQLOLEDB;Data Source=(local);Integrated Security=SSPI;Initial Catalog=Northwind")) {

         object[] meta = new object[10];
         bool read;

         OleDbCommand command = new OleDbCommand("select * from Region", connection);

         connection.Open();
         OleDbDataReader reader = command.ExecuteReader();

         if (reader.Read()) {
            do {
               int NumberOfColums = reader.GetValues(meta);

               for (int i = 0; i < NumberOfColums; i++)
                  Console.Write("{0} ", meta[i].ToString());

               Console.WriteLine();
               read = reader.Read();
            } while (read);
         }
         reader.Close();
      }
   }
}

Remarks

For most applications, the GetValues method provides an efficient means for retrieving all columns, instead of retrieving each column individually.

You can pass an Object array that contains fewer than the number of columns that are contained in the resulting row. Only the amount of data the Object array holds is copied to the array. You can also pass an Object array whose length is more than the number of columns that are contained in the resulting row.

This method returns DBNull for null database columns.

Applies to

Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

See also